2014-01-19 14 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哪裏,這是。那麼我會盡力改進我的答案。