检索所有ID [英] Retrieve all ids

查看:91
本文介绍了检索所有ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jqGrid中使用loadonce:truedatatype:json获取页面上的所有ID?

How do you get all of the ids across the pages with loadonce:true and datatype:json in a jqGrid?

推荐答案

您需要获取jqGrid的_index参数.它的对象具有id作为属性.如果您需要一个ID数组(例如getDataIDs方法),则可以执行以下操作

You need get _index parameter of jqGrid. It's object having ids as properties. If you need to have an array of ids (like with getDataIDs method) you can do the following

var id, ids = [], indexes = $("#grid").jqGrid("getGridParam", "_index");
for (id in indexes) {
    if (indexes.hasOwnProperty(id)) {
        ids.push(id);
    }
}

代码使用本地网格的ID填充ids数组.

The code fills the ids array with the ids of the local grid.

通过_index对象的值(如上面的for循环中的indexes[id])包含$("#grid").jqGrid("getGridParam", "data")数组中相应数据对象的索引.

By the way the value of the _index object (like indexes[id] in the for loop above) contains the index of the corresponding data object in the $("#grid").jqGrid("getGridParam", "data") array.

例如,如果您要用诸如此类的数据填充网格

For example if you will fill the grid with the data like

var myData = [
        {id: "x", name: "abc", age: "12"},
        {id: "y", name: "def", age: "34"}
    ];
$("#grid").jqGrid({
    data: myData,
    datatype: "local",
    colModel: [{name: "name"}, {name: "age"}]
});

然后$("#grid").jqGrid("getGridParam", "_index")将成为对象

{
    x: 0, // index of the data for the item having id="x"
    y: 1  // index of the data for the item having id="y"
}

$("#grid").jqGrid("getGridParam", "data")将是数组

[
    {name: "abc", age: "12"}
    {name: "def", age: "34"}
]

这篇关于检索所有ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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