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

时间:2015-03-10 12:09:55

标签: knockout.js jquery-plugins jqxgrid

我已经尝试了几天,搜索,尝试,调试,但我无法解决以下问题:

请参阅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' },
        ]
    });

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

我在谷歌浏览器的调试器中看到我有完整的对象。

有人提示吗?

1 个答案:

答案 0 :(得分:0)

我设法搞清楚了。

请看这个小提琴: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' }, 
]

});