javascript 剑道网格如何按字段值获取一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19276994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
kendo grid How to get a row by field value
提问by pasluc74669
I need to get a row(s) from my kendo grid, using a string as parameter to filter rows. the grid model is:
我需要从我的剑道网格中获取一行,使用字符串作为参数来过滤行。网格模型是:
{
id: "id_tipo_pagamento",
fields: {
id_tipo_pagamento: { type: "number", editable: false },
desc_tipo_pagamento: { type: "string"}
}
i tried this, but isn't working:
我试过这个,但不起作用:
var grid = $("#kendoGrid").data("kendoGrid");
var row = grid.tbody.find("tr[desc_tipo_pagamento=test]");
回答by OnaBai
Instead of using DOM, I would suggest using jQuery.grep
on the DataSource.data
array (if you want all) or in DataSource.view
if you want from the current visible ones.
我建议不要使用 DOM,而是建议jQuery.grep
在DataSource.data
数组上使用(如果你想要全部),或者DataSource.view
如果你想要从当前可见的数组中使用。
Example:
例子:
// Retrieve all data from the DataSource
var data = grid.dataSource.data();
// Find those records that have desc_tipo_pagamento set to "test"
// and return them in `res` array
var res = $.grep(data, function (d) {
return d.desc_tipo_pagamento == "test";
});
res
will contain a reference to the records in DataSource that matched the condition.
res
将包含对 DataSource 中与条件匹配的记录的引用。