从使用 js-grid 创建的 tr 获取 id,属性 path 每次都改变
Get id from tr created using js-grid, property path changes every time
所以我正在使用 js-grid 来填充通用网格。我有 4 个可见列和 1 个隐藏 ID 列。我正在尝试将每行的唯一 ID 传递给另一个函数。但是,当我使用 jquery 深入对象 return 的 属性 路径时。我需要访问的密钥嵌套在一个密钥中,该密钥似乎每次我 return 对象时都会改变。
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]')");
这是我看到的。更改的 key/keys 在附图中并以单词 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;
}
所以我正在使用 js-grid 来填充通用网格。我有 4 个可见列和 1 个隐藏 ID 列。我正在尝试将每行的唯一 ID 传递给另一个函数。但是,当我使用 jquery 深入对象 return 的 属性 路径时。我需要访问的密钥嵌套在一个密钥中,该密钥似乎每次我 return 对象时都会改变。
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]')");
这是我看到的。更改的 key/keys 在附图中并以单词 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;
}