Kendo ui kendo grid如何使用外键字段设置schema.model

Kendo ui kendo grid如何使用外键字段设置schema.model,kendo-ui,datasource,kendo-grid,kendo-combobox,Kendo Ui,Datasource,Kendo Grid,Kendo Combobox,需要有关在剑道格网中添加新记录的帮助。 我有一个带有外键字段的网格。网格由从webmethod返回的带有子对象的json数据填充。看起来是这样的: [ { "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, "indet

需要有关在剑道格网中添加新记录的帮助。 我有一个带有外键字段的网格。网格由从webmethod返回的带有子对象的json数据填充。看起来是这样的:

[
{
"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"
                }
            }
            ]

        }
];
当我编辑一行时,这些设置工作正常,网格在组合框字段中显示正确的内容。 问题是当我点击“添加新记录”按钮时,因为当它试图添加新行时,它找不到子对象字段“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 }
“添加”按钮工作正常,但加载网格时,列id_classe_iva不会显示classe_iva.desc_classe_iva字段

我如何解决这个问题??^?
提前感谢。

为了解决此问题,我使用了一种解决方法:

引发此错误的原因是,在field.template的声明中,有一个未声明的变量(classe_iva):

然后,我声明了一个全局变量

var classe_iva;
这样,当我添加一条新记录时,代码不会抛出任何错误,并且通过三元if设置默认值

希望它能帮助别人

var classe_iva;