2013-08-30 57 views
1

需要關於在kendo網格中添加新recort的幫助。 我有一個外鍵字段的網格。網格由帶有子對象的json數據填充,從webmethod返回。它看起來像這樣:kendo grid如何使用外鍵字段設置schema.model

[ 
{ 
"classe_iva": { 
    "id_classe_iva": 5, 
    "desc_classe_iva": "Esente", 
    "note_classe_iva": null 
}, 
"id_iva": 37, 
"desc_iva": "bbb", 
"codice_iva": "bbb", 
"imposta": 2, 
"indetr": 2, 
"id_classe_iva": 5, 
"note": "dddddfsf", 
"predefinito": false, 
"id_company": 4 
}, 
{ 
"classe_iva": { 
    "id_classe_iva": 6, 
    "desc_classe_iva": "Escluso", 
    "note_classe_iva": null 
}, 
"id_iva": 52, 
"desc_iva": "o", 
"codice_iva": "jj", 
"imposta": 1, 
"indetr": 1, 
"id_classe_iva": 6, 
"note": "l", 
"predefinito": false, 
"id_company": 4 
} 
] 

並且這是在數據源劍道使用的schema.model:

model = { 
    id: "id_iva", 
    fields: { 
     id_iva: { type: "string", editable: false }, 
     desc_iva: { type: "string" }, 
     codice_iva: { type: "string" }, 
     imposta: { type: "number" }, 
     indetr: { type: "number" }, 
     id_classe_iva: {type: "string"}, 
     note: { type: "string" }, 
     predefinito: { type: "boolean" }, 
     id_company: { type: "number" } 
    } 
} 

..並且在下面所示的網格列格式:

toolbar = [{ 
    name: "create", 
    text: "Aggiungi nuova aliquota IVA" 
}]; 
columns = [ 
     { field: "desc_iva", title: "Descrizione", width: 45 }, 
     { field: "codice_iva", title: "Codice", width: 45 }, 
     { field: "imposta", title: "Imposta", width: 45 }, 
     { field: "indetr", title: "Indetr", width: 45 }, 
     { field: "classe_iva.desc_classe_iva", title: "Classe IVA", width: 200, editor: categoryDropDownEditor, template: "#= classe_iva ? classe_iva.desc_classe_iva : 1 #", defaultValue: { id_classe_iva: 1, desc_classe_iva: "Acq. Intra-UE" } }, 
     { field: "note", title: "Note", width: 45 },    

     { 
      command: [{ 
       name: "destroy", 
       text: "Elimina", 
       confirmation: "Sei sicuro di voler eliminare questa voce?" 
      } ,    
      { 
       name: "edit",     
       text: { 
        edit: "Modifica", 
        update: "Aggiorna", 
        cancel: "Cancella" 
       } 
      } 
      ] 

     } 
]; 

當我編輯一行時,Theese設置正常工作,並且網格向ComboBox字段顯示正確的內容。 問題是當我點擊「添加新記錄」按鈕時,因爲當它試圖添加一個新行時,它沒有找到子對象字段「classe_iva」。

如果我改變column.field這個

{ field: "id_classe_iva", title: "Classe IVA", width: 200, editor: categoryDropDownEditor, template: "#= id_classe_iva ? id_classe_iva : 1 #", defaultValue: { id_classe_iva: 1, desc_classe_iva: "Acq. Intra-UE" } }, 
     { field: "note", title: "Note", width: 45 } 

Add按鈕工作正常,但加載網格時,該列id_classe_iva不顯示我的classe_iva.desc_classe_iva場...

我該如何解決這個問題?^? 在此先感謝。

回答

0

來解決這個問題,我用一種變通方法:

錯誤被拋出,因爲在那裏field.template其中未聲明的變量(classe_iva)聲明:

{ field: "id_classe_iva", title: "Classe IVA", width: 200, editor: categoryDropDownEditor, template: "#= classe_iva ? classe_iva.desc_classe_iva : 1 #", defaultValue: { id_classe_iva: 1, desc_classe_iva: "Acq. Intra-UE" } }, 

然後,我宣佈一個全局變量

var classe_iva; 
這樣

,當我添加一個新的記錄,代碼不會引發任何錯誤,以及如果默認值設置三元。

希望它能幫助別人。

相關問題