KendoUI Combobox配置复杂对象

时间:2014-01-19 19:25:12

标签: kendo-ui kendo-grid kendo-combobox

我将Combobox绑定到一个复杂的Object,绑定使得ID字段可用作此对象的直接属性,但Text属性来自子对象属性。

我已经能够配置它正确显示值, 但遇到问题以指定optionLabel说“select”无法指定Parent.Childproperty获取运行时错误(Uncaught TypeError:无法读取属性未定义的'Childproperty'

如何在模型定义中指定复杂对象,在下面指定空选择?

   $('<input id="DegreeDDL" name="' + options.field + '"/>').appendTo(container).kendoDropDownList({
            autoBind: true,
            serverFiltering: true,
            optionLabel: {
                'Parent.Childproperty': "--- Select ---",
                ABCD_PK: null

            },
            dataSource: {
                transport: {
                    read: {
                        url: function (e) {
                            return "api/Org/XXXXXXXX?abcdPK=" + efgh;
                        },
                        dataType: "json" // <-- The default was "jsonp"
                    }
                },
            },
            dataTextField: "Parent.ChildProperty",
            dataValueField: "ABCD_PK"
        });

在为网格定义模型时也遇到类似的问题

 var model = {
        id: "ABCD_PK",
        fields: {
            Parent.Child.ChilProperty: 
                }
             }

1 个答案:

答案 0 :(得分:1)

要回答您的第一个问题:如果在此处创建对象会导致错误,请使用optionLabel作为字符串:

optionLabel: "--- Select ---",

这是JSFiddle的工作:http://jsfiddle.net/a6Ek2/11/

要回答第二个问题,只需使用dataSource.schema解析json中的非复杂对象。本主题中的更多内容:How can I use nested Json to populate Kendo UI grid?。网格官方不处理复杂的数据对象。但是如果你想尝试一下,你只能在模型中说明父对象,例如:

fields: {
    ABCD_PK: { editable: false },
    Parent: { editable: true },
}

如果你仍然遇到问题,只需更新这个JSFiddle并显示它的位置。我会尝试改进我的答案。

相关问题