【问题标题】:KendoUI Grid with custom dropdown column passing whole object instead of Id带有自定义下拉列的 KendoUI Grid 传递整个对象而不是 Id
【发布时间】:2014-08-13 18:27:16
【问题描述】:

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

Id(guid), Name, Description, CategoryId(guid)

当下拉菜单被改变时,它会触发一个保存命令并像这样发回:

Id(guid), Name, Description, Category(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 '';
    }

这是主要数据源的架构:

schema: {
    model: {
       id: 'Id',
       fields: {
         categoryName: { editable: true },
         categoryDesc: { editable: true },
         categoryId: { editable: true }
       }
    }
}

【问题讨论】:

  • 在模型中尝试将类型设置为字符串 categoryId: { editable: true , type: "string" },

标签: angularjs kendo-ui kendo-grid odata breeze


【解决方案1】:

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
           });
    }

【讨论】:

  • 非常感谢。我想知道:你在哪里找到那个财产?我查看了谷歌,找不到任何东西,比如配置属性列表。
  • 我不记得了。我想我只是碰巧看到了一个例子,然后碰巧查了一下。
猜你喜欢
  • 1970-01-01
  • 2012-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-16
  • 2020-09-06
  • 1970-01-01
相关资源
最近更新 更多