首页 文章

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

提问于
浏览
1

需要有关在kendo网格中添加新的重新排序的帮助 . 我有一个带有外键字段的网格 . 网格由带有子对象的json数据填充,从web方法返回 . 它看起来像这样:

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

这是kendo数据源中使用的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设置工作正常,并且网格在组合框字段中显示正确的内容 . 问题是当我点击“添加新记录”按钮时,因为当它尝试添加新行时,它找不到子对象字段“classe_iva” .

如果我将column.field更改为this

{ 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字段...

我怎么能解决这个问题?? ^?提前致谢 .

1 回答

  • 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;
    

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

    希望它会帮助某人 .

相关问题