Kendo DropDownList与Kendo Grid的默认项目绑定

474

我想将剑道下拉列表添加到我的网格中。除了一件事,一切都会好起来的。当我想使用默认的kendo创建工具栏“添加记录”时,我无法绑定从dropdownlist数据源获取的第一个值。

数据源工作正常。Dropdownlist也可以正常工作。如果我从下拉列表中手动选择任何内容,则一切正常。

 $scope.mainGridOptions = {

                dataSource: {
                    transport: ...
                    schema: ...
                },

                batch: false,
                       ...    
                toolbar: ["create"],
                columns: [
                    ...,{

                    field: "location_id",
                    title: "Location",

                    editor: function(container,options){

                                var input = $('<input/>');
                                input.attr('name',options.field);
                                input.appendTo(container);

                                input.kendoDropDownList({
                                    autoBind: true,
                                    dataTextField: "text",
                                    dataValueField: "value",
                                    dataSource: locationsDataSource,
                                    index: 0,
                                });
                            }
                    },
                  ...
                ]
            };

我也尝试过 除了“索引”,我试图从dataSource中手动选择第一项。在视觉上,它工作正常。即使也选择了“第三项”,但是当我单击“更新”时,数据不受限制。

input.kendoDropDownList({
     autoBind: true,
     dataTextField: "text",
     dataValueField: "value",
     dataSource: locationsDataSource,
     dataBound: function(e){
        this.select(0);
     }
});

任何人?

474

因此,我找到了解决方案。

这似乎是Kendo DropDownList的错误。

我从下拉dataBound事件加载dataSource之后手动将其绑定。

开始了:

editor: function(container,options){

        var input = $('<input/>');
        input.attr('name',options.field);
        input.attr('data-bind','value:' + options.field);
        input.appendTo(container);

        input.kendoDropDownList({
            autoBind: true,
            dataTextField: "text",
            dataValueField: "value",
            dataSource: locationsDataSource,
            index: 0,
            dataBound: function(){

                options.model[options.field] = this.dataItem().value;

            }//end databound

        });//end dropdownlist

}//end editor

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章