我正在使用Kendo UI网格并显示模型的角色。每个模型都有一个导航属性,我试图显示此导航属性中存在的字段。

  //schema for my kendo data source
  schema: {
                data: function (data) {
                    return data || [];
                }
            }
 ......................................................
   $("#FAAFreqGrid").kendoGrid({
            dataSource: FAADS,

            columns: [
                   { field: "Id", title: "Freq ID", format: "{0:c}", width: "120px" },
                 { field: "Frequency", title: "Frequency Test" format: "{0:c}", width: "120px" },
                  { field: "FREQ_POOL", title: "FAATEST", format: "{0:c}", width: "120px" },
                { command: ["edit", "destroy"], title: " ", width: "250px" }
            ],
            toolbar: ["create"],
            editable: "inline",
            pageable: true

        });


如果转到Web API网址,则会收到以下内容的json响应:

[{"$id":"1","Frequency":"164.1375","FREQ_POOL":{"$id":"2","IsAM":true,......etc}


FREQ_POOL是我的导航属性,它具有我想要的数据。频率存在并正确显示在我的网格中。但是我的FREQ_POOL字段显示为[object Object],如果我尝试说“ FREQ_POOL.IsAM”,则表示未定义IsAM。我无法将其绑定到可以绑定到任何其他非导航字段的任何属性。我该如何工作?数据存在于返回的JSON对象中,但是绑定无法正常工作。谢谢。

最佳答案

您可以为相关列设置模板,如下所示:

$("#grid").kendoGrid({
  columns: [ {
    field: "name",
    template: "<strong>#: name.first#, #: name.last# </strong>"
  }],
  dataSource: [ { name: { first: 'Jane', last: 'Doe' } }, { name: { first: "John", last: 'Doe' } } ]
});


然后可以使用模板在数据集中显示对象

更多信息,您可以找到here

对于编辑,您还可以定义单元格编辑器,以及其他模板或功能,有关更多信息,您可以找到here

关于javascript - Kendo UI网格-绑定(bind)到导航属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28998383/

10-14 22:56
查看更多