0

サーバーからデータをロードするjqgridを作成しました。グリッドでデータを表示できますが、拡張して起動しようとするとonclickSubmit$.jgrid.del実際のレコードIDを取得できません(これは私の場合、それは 101 、 102 です) 1 、 2 を返す代わりに、行インデックスIDである可能性があります。

JqG​​rid

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引数に次のものが含まれます

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);
    }
4

2 に答える 2

2

ここのドキュメントを見ると、jsonReader で id プロパティ名を指定する必要があると思います。

jsonReader : { repeatitems: false, id: "e_info_id" }
于 2012-03-29T13:49:26.100 に答える
0

jqGridを使用するjsonReader: { repeatitems: false }場合、その名前のrowidとしてどの値を使用する必要があるかわかりません。rowidは、グリッド内の要素のid属性の値です。<tr>

この問題を解決するには、次の2つのオプションがあります。

  1. key: true列にプロパティを定義しe_info_idます。
  2. で使用するid: "e_info_id"にはjsonReader(クリスチャンの答えを参照)

idのプロパティのデフォルト値jsonReaderはですid: "id"

id値はページ上で一意である必要があることを知っておくことが重要です。たとえば、ページに2つのグリッドがあり、両方に整数IDの情報がある場合、競合が発生する可能性があります。オプションを使用できるidPrefix場合。要素のid属性の値が(原因の両方のページで異なるはずです)と「標準」から構築される場合。<tr>idPrefixid

于 2012-03-29T14:08:21.167 に答える