KendoUI Grid使用自定义下拉列传递整个对象而不是Id

Boo*_*one 3 odata kendo-ui angularjs breeze kendo-grid

我正在使用Angular/Breeze的Kendo UI.我有一个可编辑的网格,其中一列是下拉菜单.一切正常,直到保存发生.问题是我的odata电话期待:

Id(guid),名称,描述,CategoryId(guid)

当下拉列表被更改时,它会触发一个save命令并发回如下:

Id(guid),名称,描述,类别(categoryId,Name,Desc)

在哪里以及如何使网格仅发送categoryId而不是整个类别对象?

    vm.columns = [
        { field: 'name', title: 'name' },
        { field: 'desc', title: 'description' },
        {
            field: 'categoryId',
            title: 'group',
            template: getCategory,
            editor: categoryDropDown
        }
    ];

    function categoryDropDown(container, options) {
        $('<input data-text-field="categoryName" data-value-field="categoryId" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                dataTextField: "categoryName",
                dataValueField: "categoryId",
                dataSource: vm.categories
            });
    }

    function getCategory(item) {
        for (var i = 0, length = vm.category; i < length; i++) {
            console.log(vm.categories[i].categoryId);
            if (vm.categories[i].categoryId === item.categoryId) {
                return vm.categories[i].categoryName;
            }
        }
        return '';
    }
Run Code Online (Sandbox Code Playgroud)

以下是主数据源的架构:

     schema: {
            model: {
                id: 'Id',
                fields: {
                    categoryName: { editable: true },
                    categoryDesc: { editable: true },
                    categoryId: { editable: true }
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

Boo*_*one 6

valuePrimitive是缺少的键

    function categoryDropDown(container, options) {
       $('<input data-text-field="categoryName" data-value-field="categoryId" data-bind="value:' + options.field + '"/>')
           .appendTo(container)
           .kendoDropDownList({
               dataTextField: "categoryName",
               dataValueField: "categoryId",
               dataSource: vm.categories,
               valuePrimitive: true
           });
    }
Run Code Online (Sandbox Code Playgroud)