Kendo Grid,单元格编辑 - >如何将所选ID从自动完成设置为模型以进行更新操作?

时间:2014-11-05 13:53:35

标签: jquery autocomplete kendo-ui kendo-grid

我在Kendo Grid中有以下列和模型定义:

 schema: {
                model: {     parentProject: {
                                editable: true,
                                nullable: false,
                                type: "string"
                            },

columns: [

{
                    field :"parentProject",
                    title : $translate.instant('PARENT_PROJECT'),
                    editor: GlobalHelperService.getProjectsListForAutocomplete,
                    width: 250,
                    filterable: {
                        cell: {
                            operator: "contains"
                        }
                    }
                },

对于上面定义的列上的自动完成,我有以下内容。

this.getProjectsListForAutocomplete =  function (container, options) {
         var input = $('<input id= "selecteditem" data-bind= "value:' +  options.field + '" />');
         input.appendTo(container);
         input.kendoAutoComplete({
             dataSource :  {
                 type: "json",
                 serverFiltering: true,
                 transport: {
                     read: function (options) {
                         console.log("List");
                         console.log(options.data);
                         requestParams = {
                             "entityName": "project",
                             "page": 1,
                             "pageSize": 20,
                             "filter": options.data.filter,
                             "sort": [
                                 {
                                     "field": "dic",
                                     "ord": "asc"
                                 }
                             ]
                         };
                         ApiService.doHttpRequest(
                             "POST",
                             $rootScope.apiBaseUrl + "project/search",
                             requestParams
                         )
                             .success(function (data, status, headers, config) {
                                 // successful data retrieval
                                 console.log("request success, checking state");
                                 console.log(data);
                                 // sent status to global HTTP status service
                                 var jsonResponse =  ApiService.processReturnedHttpState(status);
                                 console.log("Status response is " + jsonResponse.result);
                                 // do something with data
                                 switch (jsonResponse.result) {
                                     case true:
                                         options.success(data.results);
                                         break;
                                     case false:
                                         growlNotifications.add($translate.instant('LIST_LOADING_ERROR'), 'error',  $rootScope.notificationLifetime);
                                         break;
                                 }
                             })
                             .error(function (data, status, headers, config) {
                                 var jsonResponse =  ApiService.processReturnedHttpState(status);
                                 console.log("Processing error with status " +status);
                                 growlNotifications.add($translate.instant('PROCESSING_REQUEST_ERROR') + jsonResponse.message , 'error',  $rootScope.notificationLifetime);
                                 // hide loading spinner
                                 kendo.ui.progress(gridView, false);
                             });
                     }
                 }
             },
             dataTextField: "name"  ,
             dataValueField: "id",
             filter: "contains",
             minLength: 1,
             change  : function (e) {
                 console.log("change");
                 //console.log(e);
                 //gridView.closeCell();
             },
             select  : function (e) {
                 console.log("select");
                 var dataItem = this.dataItem(e.item.index());
                 console.log(dataItem);
                 return dataItem;
             }
         });
     };

问题是,通过从自动填充中选择项目更改单元格内容后,模型更新了选定的名称而不是ID。

这意味着自动填充中的选定值应替换模型中的项目,因此在更新请求中将包含所选ID的项目 parentProject 值。

我该怎么办?

编辑:

我试图这样做,但没有运气。

 change  : function (e) {
                 console.log("change");
                 //console.log(e);
                 //gridView.closeCell();
                 e.sender.value("New Value");
                 options.model.set(options.field, "123");
             },

它始终只更改单元格中的文本。

1 个答案:

答案 0 :(得分:0)

我不是很想你。

但我得到的是你必须在架构模型中指定id和字段。

   schema: {
               model: {
                  id: "YOUR PROJECT ID",
                  fields: {
                            parentProject: {
                                    editable: true,
                                    nullable: false,
                                    type: "string"
                             }
                          }
                      }
              }

希望得到帮助