无法获取实际的记录ID [英] not able to get the actual record id

查看:142
本文介绍了无法获取实际的记录ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have create the the jqgrid which loads the data from the server , i am able to view the data in a grid , but when i try to extend and fire up onclickSubmit of $.jgrid.del i am not be able to get the actual record id (which is in my case it is 101 , 102 ) instead of that it returns 1 , 2 , may be a row index 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读取器中指定id可以解决删除记录的问题,但是当我编辑记录时,postdata参数包含

Well specifying id in json reader solved my problem in deleting record , but when i edit the record my postdata argument contains

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

and when i try to access it as postdata.id or postdata.e_info_id it returns undefined , here is the onclickSubmit of edit

 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是网格中<tr>元素的id属性的值.

If you use jsonReader: { repeatitems: false } jqGrid don't know which values it should use as so named rowid. The rowid is the value of id attribute of <tr> elements in the grid.

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

To fix the problem you have two options:

  1. 要在e_info_id列中定义key: true属性.
  2. 要在jsonReader中使用id: "e_info_id"(请参见克里斯蒂安的答案)
  1. To define key: true property in the e_info_id column.
  2. To use id: "e_info_id" in jsonReader (see the answer of Christian)

jsonReaderid属性的默认值为id: "id".

重要的是要知道页面上的id值必须唯一.例如,如果您在页面上有两个网格,并且都具有带有整数ID的信息,则可能会发生冲突.在这种情况下,您可以使用idPrefix选项.如果<tr>元素的id属性值将由idPrefix(在两个原因页面中应该不同)和标准" id构造.

It's important to know that the id value have to be unique on the page. If you for example have two grids on the page and both have information with integer ids you can have conflicts. In the case you can use idPrefix option. In the case the value of id attribute of <tr> elements will be constructed from the idPrefix (which should be different in both pages of cause) and the "standard" id.

这篇关于无法获取实际的记录ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆