我已经创建了从服务器加载数据的jqgrid,我能够在网格中查看数据,但是当我尝试扩展并激活onclickSubmit
的$.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": "",
}
]
}
那么指定ID的JSON读者解决了我的问题,在删除记录,但是当我编辑的记录我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: function (options, postdata) {
console.log(postdata);
console.log(postdata.id); //undefined
options.url = options.editurl +'/' + encodeURIComponent(postdata.id);
}
关于'onclickSubmit':请仔细阅读您的上一个问题[我的答案](http://stackoverflow.com/a/9923417/315935)。拥有'id'的'postdata'的属性具有* not *名称'id'。在你的情况下它将是'eventGrid_id'。属性名称由网格的“id”和“_id”文本构成:'gridId +“_id”'。 – Oleg 2012-03-29 14:18:31
如果您要为问题添加“jquery”或“javascript”标记,则代码将以JavaScript特定颜色标记。 – Oleg 2012-03-29 15:46:09