Kendo UI嵌套网格不绑定到字段

时间:2018-06-24 07:51:11

标签: kendo-ui kendo-grid kendo-datasource

我想创建一个嵌套的网格以显示和编辑带有各自问题的调查清单。问题是我要对网格进行“ incell”编辑和一个“ Save”按钮(而不是自动保存)。

数据采用以下格式:

[
  id:1,
  translations: {
    'en-US': {name: 'Survey 1'},
    'el-GR': {name: 'Survey 1'},
  },
  questions:[
    id:1,
    translations:{
        'en-US': {text: 'Question 1'},
        'el-GR': {text: 'Ερώτηση 1'},
    },
  ],
]

我的数据源具有传输CRUD URL(到我的API)和以下架构:

"model": {
    "id": "id",
    "fields": {
        "id": {"type": "Number", "editable": false},
        "translations": {"defaultValue": {"en-US": {}, "el-GR": {}}},
        "name_en_US": {
            "name": "name_en_US",
            "field": "translations['en-US'].name",
            "defaultValue": "New Survey",
            "validation": {
                "required": true
            }
        },
        "name_el_GR": {
            "name": "name_el_GR",
            "field": "translations['el-GR'].name",
            "defaultValue": "New Survey",
            "validation": {
                "required": true
            }
        },
        "questions": {"defaultValue": []}
    }
}

和网格列如下:

{
    "title": "en-US",
    "columns": [{"field": "name_en_US", "title": "Name"}]
},
{
    "title": "el-GR",
    "columns": [{"field": "name_el_GR", "title": "Name"}]
}

到目前为止,效果很好。

问题来自于嵌套网格,我尝试对嵌套数据重复相同的架构-列过程,只是嵌套网格的数据源如下所示

grid.detailInit = function (e) {

    let schema = {
        "model": {
            "id": "id",
            "fields": {
                "id": {
                    "type": "Number",
                    "editable": false
                },
                "translations": {
                    "defaultValue": {
                        "en-US": {},
                        "el-GR": {}
                    }
                },
                "text_en_US": {
                    "name": "text_en_US",
                    "field": "translations['en-US'].text",
                    "defaultValue": "New Question",
                    "validation": {"required": true}
                },
                "text_el_GR": {
                    "name": "text_el_GR",
                    "field": "translations['el-GR'].text",
                    "defaultValue": "New Question",
                    "validation": {"required": true}
                }
            }
        }
    };
    let columns = [
        {
            "title": "en-US",
            "columns": [{"field": "text_en_US", "title": "Question"}]
        },
        {
            "title": "el-GR",
            "columns": [{"field": "text_el_GR", "title": "Question"}
            ]
        }
    ];

    $("<div name='surveyQuestions'/>").appendTo(e.detailCell).kendoGrid({
        dataSource: {
            data: e.data.questions,
            schema: schema,
            pageSize: 10,
        },
        columns: columns,
        editable: 'incell',
        scrollable: false,
        sortable: true,
        pageable: true,
        toolbar: [{name: "create"}, {name: "cancel"}],
    });
};

现在这些字段未绑定到translations['en-US'].text,但数据停留在text_en_US并按以下方式传输:

"questions": [{
    "id": 0,
    "translations": {"en-US": {}, "el-GR": {}},
    "text_en_US": "New Question 1",
    "text_el_GR": "New Question 2"
}],
"translations": {
    "el-GR": { "name": "New Survey 1" },
    "en-US": { "name": "New Survey 1" }
},
"id": 1

如果我激活自动同步或按嵌套网格的“保存”按钮,则一切正常,但丢失了“已更改标记”网格(左上角的红色三角形)。

"questions": [{
    "id": 0,
    "translations": {
        "en-US": {"text": "New Question 1"},
        "el-GR": {"text": "New Question 2"}
    },
    "text_en_US": "New Question 1",
    "text_el_GR": "New Question 2"
}
],
"translations": {
    "el-GR": {"name": "New Survey 1",},
    "en-US": {"name": "New Survey 1",}
},
"id": 1

似乎直到保存后才绑定。但是我不明白为什么绑定了单个属性(text_en_US)而没有绑定该字段。

0 个答案:

没有答案