2016-07-02 66 views
0

我想实现kendo网格自定义编辑器(下拉列表)。kendo网格自定义编辑发送[对象对象]

一切都很是不错,但如果创建新的记录或更新存在的记录时,下拉栏为空我得到了更新错误,在调试时,我看到 “的翻译:”发为大陆柱, 的价值,但是当下拉列有价值我可以改变下拉值和更新记录是好的!

我的代码是:

var crudServiceBaseUrl = "http://localhost:8090/hr"; 

var countryDataSource = 
     new kendo.data.DataSource({ 
       transport: { 
          parameterMap: function(options, operation) { 
           if (operation !== "read" && options.models) { 
            return { 
             models: kendo.stringify(options.models) 
            }; 
           } 
          }, 
          read: { 
            url: crudServiceBaseUrl + "/countries", 
            dataType: "jsonp" 
           }, 
           update: { 
            url: crudServiceBaseUrl + "/countries/Update", 
            dataType: "jsonp" 
           }, 
           destroy: { 
            url: crudServiceBaseUrl + "/countries/Destroy", 
            dataType: "jsonp" 
           }, 
           create: { 
            url: crudServiceBaseUrl + "/countries/Create", 
            dataType: "jsonp" 
           } 
       }, 
       schema : { 
        data : "items" 
        }, 
       model: {id : "CD_CONT", 
         fields: { 
          CD_CONT : { type: "string",editable : false}, 
          NAME_CONT : { type: "string",editable : true,nullable : false}, 
          CONTINENT : { type: "string",editable : true,nullable : true} 
         } 
        } 
      }); 


var continentDataSource = new kendo.data.DataSource({ 
    data: [ { continent:"1",name:"asia"}, 
      { continent:"2",name:"europ"}, 
      { continent:"3",name:"america"} 
      ] 
}); 

$('#grid).kendoGrid({ 
      toolbar: ["create","save", "cancel",], 
      columns: [ 
       { 
        field: "CD_CONT" , 
        title: "Cd cont" 
       }, 
       { 
        field: "NAME_CONT" , 
        title: "Name cont" 
       }, 
       { 
        field: "CONTINENT" , 
        title: "Continent", 
        editor: function ContinentDropDown(container, options) { 
             $('<input data-text-field="name" data-value-field="continent" data-bind="value:' + options.field + '"/>') 
              .appendTo(container) 
              .kendoDropDownList({ 
               dataSource: continentDataSource, 
               dataTextField: "name", 
               dataValueField: "continent" 
              }); 
            } 
       } 
       ], 
      dataSource: countryDataSource , 
      editable: "inline" 
     }); 

还怎么设置字段模板,以显示网格大陆textValue?

回答

0

您忘了在编辑器中添加name吗?

$('<input data-text-field="name" data-value-field="continent" data-bind="value:' + options.field + '" name='" + options.field + "'/>')