Javascript 从使用js网格创建的tr获取id,属性路径每次都会更改
所以我使用js网格来填充一个通用网格。我有4个可见列和1个隐藏id列。我试图将每行的唯一id传递给另一个函数。但是,当我使用jquery深入研究对象返回的属性路径时。我需要访问的键嵌套在一个键中,该键似乎在每次返回对象时都会更改Javascript 从使用js网格创建的tr获取id,属性路径每次都会更改,javascript,jquery,jsgrid,Javascript,Jquery,Jsgrid,所以我使用js网格来填充一个通用网格。我有4个可见列和1个隐藏id列。我试图将每行的唯一id传递给另一个函数。但是,当我使用jquery深入研究对象返回的属性路径时。我需要访问的键嵌套在一个键中,该键似乎在每次返回对象时都会更改 Here's the JS grid code... $("#jsGrid").jsGrid({ width: "100%", height: "25rem", autoload: true, inser
Here's the JS grid code...
$("#jsGrid").jsGrid({
width: "100%",
height: "25rem",
autoload: true,
inserting: false,
editing: false,
sorting: false,
paging: true,
pageloading: true,
data: data,
fields: [
{ name: "ID", type: "text", width: 25, align: "center", visible: false },
{ name: "Date", type: "text", width: 25, align: "center" },
{ name: "Color", type: "text", width: 25, align: "center" },
{ name: "type", type: "text", width: 25, align: "center" },
{ name: "other", type: "text", width: 25, align: "center" }
]
});
Here's some sample data...
var data = [
{ "ID": "123", "Date": "3/15/19", "color": "Brown", "type": "something", "other": "7 mins" },
{ "ID": "124", "Date": "3/15/19", "color": "Red", "type": "something", "other": "15 mins" },
{ "ID": "125", "Date": "3/15/19", "color": "Blue", "type": "something", "other": "15 mins" },
{ "ID": "126", "Date": "3/15/19", "color": "Blue", "type": "something", "other": "7 mins" },
{ "ID": "127", "Date": "3/15/19", "color": "Black", "type": "something", "other": "20 mins" },
{ "ID": "128", "Date": "3/15/19", "color": "Gold", "type": "something", "other": "5 mins" },
{ "Date": "TOTAL", "color": "", "type": "", "other": "74 mins"}
];
Here's the code I use to get the <tr> object using console
$(".jsgrid-table > tbody > tr:not('[class*=totalsRow]')");
这是我看到的。所更改的键位于所附图像中,并以单词jQuery开头
所以我尝试了你的代码。根据您给我的,我必须编写自定义方法来实现它
var k = $('.jsgrid-table > tbody > tr');
Items = GetMatchingProperties(k, 'jQuery'); //'jQuery' This is the word that matches
console.log(Items);
function GetMatchingProperties(items, attribName) {
var list = [];
$(items).each(function(i, t) {
var $t = $(t);
var keys = Object.keys($t[0]);
var JQueryKey = keys.filter(function(x){
if(x.match(attribName)){
return x;
}
});
$.each(JQueryKey, function(i, v){
list.push( $t[0][v] );
});
});
return list;
}
对不起,我确实看到了数据。我看不到JQuery号码或类似的东西?你在用chrome吗@泽塔瓦萨:对不起。您是否正在使用其他浏览器?我想我错过了什么。等等,你是怎么安慰它的。粘贴console.log代码。@zetawars您可以使用-console.log$'.jsgrid table>tbody>tr';