jqGrid选择不更新onchange(C#MVC)

问题描述:

我通过dataInit中的ajax调用加载数据,它的工作原理和一切正常,但没有我的列(只有下拉列)不设置id值。jqGrid选择不更新onchange(C#MVC)

例如我有itemId和itemCode属性。我加载数据并正确显示,但如果我更改下拉列表中的值,那么它不会绑定/更新我的itemId值。

基本上我想下拉列表绑定到我的ID列,因此当保存它我得到一个ID保存。

,{ 
        key: false, 
        hidden: true, 
        name: 'itemId', 
        index: 'itemId', 
        editable: false 
       }, { 
        key: false, 
        name: 'itemCode', 
        index: 'itemId', 
        editable: true, 
        edittype: 'select', 
        editoptions: { 
         dataInit: function(element) { 
          $.ajax({ 
           url: '@Url.Action("GetItems", "Maintenance")', 
           dataType: 'json', 
           type: 'POST', 
           success: function(response) { 
            var array = response; 
            if (array != null) { 
             var i; 
             for (i in array) { 
              if (array.hasOwnProperty(i)) { 
               if (itemId == array[i].id) { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 " selected>" + 
                 array[i].code + 
                 "</option>"); 
               } else { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 ">" + 
                 array[i].code + 
                 "</option>"); 
               } 
              } 
             } 
            } 
           } 
          }); 
         } 
        }, 
        editrules: { required: true} 

这是我的答案.....看看数据事件。我找到所选的行,然后设置单元格。控制台日志只是为了测试。

{ 
        key: false, 
        hidden: true, 
        name: 'userId', 
        index: 'userId', 
        editable: false 
       }, { 
        key: false, 
        name: 'userName', 
        index: 'userName', 
        editable: true, 
        edittype: 'select', 
        editoptions: { 
         dataInit: function(element) { 
          $.ajax({ 
           url: '@Url.Action("GetUsers", "Maintenance")', 
           dataType: 'json', 
           type: 'POST', 
           success: function(response) { 
            var array = response; 
            if (array != null) { 
             var i; 
             for (i in array) { 
              if (array.hasOwnProperty(i)) { 
               if (userId == array[i].id) { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 " selected>" + 
                 array[i].userName + 
                 "</option>"); 
               } else { 
                $(element).append("<option value=" + 
                 array[i].id + 
                 ">" + 
                 array[i].userName + 
                 "</option>"); 
               } 
              } 
             } 
            } 
           } 
          }); 
         }, 
         dataEvents: [ 
          { type: 'change', 
           fn: function (e) { 
            var rowId = $("#jqgrid").jqGrid('getGridParam', 'selrow'); 
            $('#jqgrid').jqGrid('setCell', rowId, 'userId', $(e.target).val()); 
            console.log($("#jqgrid").jqGrid('getCell', rowId, 'userId')); 
           } 
          } 
         ] 
        }