无法获得实际的记录ID

我已经创建了从服务器加载数据的jqgrid,我能够在网格中查看数据,但是当我尝试扩展并启动$.jgrid.del时,我无法获得实际数据记录id(在我的情况下是101,102)而不是它返回1,2,可以是行索引id。

jqGrid的

 jQuery("#eventGrid").jqGrid({ url:"/eventAllInfo", datatype: "json", restful: true, mtype: 'GET', width:900, colNames:['id','title', 'description'], colModel:[ {name:'e_info_id',index:'e_info_id', width:60, sorttype:"int",editable:true,editoptions:{size:10}}, {name:'e_meta_title',index:'e_meta_title', width:90,editable:true,editoptions:{size:10}}, {name:'e_meta_description',index:'e_meta_description', width:100,editable:true,editoptions:{size:10}}, ], rowNum:10, rowList:[10,20,30], jsonReader : { repeatitems: false }, pager: '#pager', caption: "Show Events" }); 

JSON响应

 { "success": true, "message": "Records Retrieved Successfully -EventAllInfo", "page": "1", "total": 1, "records": "2", "rows": [ { "e_info_id": "101", "e_meta_title": "Oracle Business Summit", "e_meta_description": null, "e_meta_img": null, "e_meta_video": null, }, { "e_info_id": "102", "e_meta_title": "Expo 2014 - Environment", "e_meta_description": "", "e_meta_img": "", "e_meta_video": "", } ] } 

在json reader中指定id解决了我删除记录的问题,但是当我编辑记录时,我的postdata参数包含了

 e_info_id: "101" e_meta_description: "" e_meta_title: "Oracle Business Summit" id: "101" oper: "edit" 

当我尝试以postdata.id或postdata.e_info_id访问它时,它返回undefined,这里是编辑的onclickSubmit

  onclickSubmit: function (options, postdata) { console.log(postdata); console.log(postdata.id); //undefined options.url = options.editurl +'/' + encodeURIComponent(postdata.id); } 

如果你使用jsonReader: { repeatitems: false } jqGrid不知道它应该使用哪个值如此命名为rowid。 rowid是网格中

元素的id属性的值。

要解决此问题,您有两种选择:

  1. e_info_id列中定义key: true属性。
  2. jsonReader使用id: "e_info_id" (参见Christian的回答)

jsonReaderid属性的默认值是id: "id"

重要的是要知道id值必须在页面上是唯一的。 例如,如果您在页面上有两个网格,并且两个网格都包含整数ID信息,则可能会发生冲突。 在这种情况下,您可以使用idPrefix选项。 在这种情况下,

元素的id属性的值将从idPrefix (在两个原因页面中应该是不同的)和“标准” id构造。

看一下这里的文档,我认为你应该在jsonReader中指定你的id属性名。

 jsonReader : { repeatitems: false, id: "e_info_id" }