【问题标题】:Kendo UI Grid - Binding to navigation propertiesKendo UI Grid - 绑定到导航属性
【发布时间】:2015-05-13 22:29:21
【问题描述】:

我正在使用 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 对象中,但绑定无法正常工作。谢谢。

【问题讨论】:

    标签: javascript asp.net-web-api kendo-ui kendo-grid


    【解决方案1】:

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

    $("#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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    相关资源
    最近更新 更多