kendo网格中组合框的默认值

时间:2015-07-21 09:11:38

标签: c# kendo-ui kendo-grid

我将组合框添加到Kendo Grid中,如下例所示: http://demos.telerik.com/kendo-ui/grid/editing-custom

    schema: {
         data: "Data",
         total: "Total",
         errors: "Errors",
         model: {
             id: "Id",
             fields: {
                CityId: {
                  editable: true,
                  type: "number",
                  validation: { required: true }
                         }, ...

    columns: [{
         field: "CityId",
         title: "City",
         editor: cityDropDownEditor,
         template: "#=City.Name#",
         width: 200,
             } ...


             function cityDropDownEditor(container, options) {
                    $('<input required data-text-field="CityName" data-value-field="CityId" data-bind="value:' + options.field + '"/>')
                        .appendTo(container)
                        .kendoComboBox({
                        autoBind: true,
                        dataTextField: "CityName",
                        dataValueField: "CityId",
                        filter: "contains",
                        index: 1,
                        autocomplete: true,
                        dataSource: {
                            transport: {
                                read:
                                {
                                url: "/Contact/GetCities",
                                type: "POST",
                                dataType: "json"
                            }
                        }
                    }});                    
                }

如果我点击添加按钮,组合框显示预填充值0.如果我删除模式中的行type: "number" - 组合框显示CityName的预填充值,其索引在组合框初始化中设置

.kendoComboBox({
 index: 1...

但是当我点击提交时,这个值没有到达后端,我看到异常。如何为组合框添加正确的默认值?

1 个答案:

答案 0 :(得分:0)

首先请注意,您已dataTextField: "CityName", dataValueField: "CityId"两次启动,并认为您错过了示例中的某些内容,这是模式中的这一部分

fields: {
    ProductID: { editable: false, nullable: true },
    ProductName: { validation: { required: true } },
    Category: { defaultValue: { CategoryID: 3, CategoryName: "Confections"} },
    UnitPrice: { type: "number", validation: { required: true, min: 1} }
 }

类别字段中,他们将默认值设置为{ CategoryID: 1, CategoryName: "Beverages"},现在我将其更改为{CategoryID:3,CategoryName:“Confections”}。它在这里运作良好

  

DEMO