2014-01-19 15 views
1

我将组合框绑定到一个复杂的对象上,绑定是这样的,即ID字段作为此对象的直接属性可用,但文本属性来自子对象属性。复杂对象的KendoUI组合框配置

我已经能够配置它正确显示的值,但运行到问题指定optionLabel说:“选择”不能够指定Parent.Childproperty获得运行时错误(遗漏的类型错误:无法读取属性“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: 
       } 
      } 
+0

我不想抱怨,但这是DropDownList不是ComboBOx正如你在标题中提到的,在你的代码中,你有'dataTextField:“Parent.ChildProperty”',然后'Parent.Child.ChilProperty:''Child'财产后父母和冒号后没有任何东西。请修正您的代码。 –

回答

1

要回答你的第一个问题定义模型时,也遇到了类似的propblem:使用optionLabel作为字符串如果在这里创建对象会导致错误:

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

这里正在工作JSFiddle:http://jsfiddle.net/a6Ek2/11/

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

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

如果你仍然有问题,这只是更新此的jsfiddle并显示exacly哪里,这是。那么我会尽力改进我的答案。