如何将 ko.observable 子对象映射到 jquery 网格

How to map ko.observable child object to jquery grid

经过几天的努力,搜索,尝试,调试,还是无法解决以下问题:

请从 knocout 可观察数组中查看 1 个对象:

Code: "CT001"
Description: "CT Neck"
Duration: 15
IsActive: true
IsSchedulingRequired: true
ModalityType: Object
             Code: "CT"
             Name: null
__proto__: ObjectStudyID: 2

我正在尝试将整个对象(包括子对象)绑定到 jquery 网格,使用:

self.studies = ko.observableArray();

var studyGridSource = {
        localdata: self.studies,
        datatype: "observablearray"
    }

var studiesDataAdapter = new $.jqx.dataAdapter(studyGridSource);

$('#studiesGrid').jqxGrid({
        source: studiesDataAdapter,
        columns: [
            { text: "Description", datafield: 'Description' },
            { text: 'Duration', datafield: 'Duration' },
            { text: 'Code', map: 'ModalityType>Code' },
        ]
    });

填充网格时,它很好地显示了描述和持续时间,但代码列保持为空。

我在 google chrome 的调试器中看到我有完整的对象。

有人有什么建议吗?

我想通了。

请看这个fiddle:http://jsfiddle.net/x5jdu7xv/6/

self.studies = [
{
    Description: "CT Neck",
    Duration: 15,
    ModalityType: { Code: "CT", Name: null }
}
];

var studyGridSource = {
localdata: self.studies,
datafields: [
    { name: "Description", datafield: 'Description' }, 
    { name: 'Duration', datafield: 'Duration' }, 
    { name: 'Code', map: 'ModalityType>Code' }, 
    ]
};

var studiesDataAdapter = new $.jqx.dataAdapter(studyGridSource);

$('#studiesGrid').jqxGrid({
source: studiesDataAdapter,columns: [
    { text: "Description", datafield: 'Description' }, 
    { text: 'Duration', datafield: 'Duration' }, 
    { text: 'Code', datafield: 'Code' }, 
]

});