检索所有ID [英] Retrieve all ids
问题描述
如何在jqGrid中使用loadonce:true
和datatype: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屋!