如何使用运算符"在"中过滤kendo数据源? 例如:
var original_data = [
{"group": [1, 2], "name": "Coca Cola"},
{"group": [1, 3], "name": "Pizza"}
];
function filter_articles(original_data, group) {
return new kendo.data.DataSource({
data: original_data,
filter: { field: 'group', operator: 'in', value: parseInt(group) }
});
}
答案 0 :(得分:1)
DataSource过滤器选项不支持此功能,因此您必须在创建数据源之前过滤数据,例如:像这样:
var original_data = [{
"group": [1, 2],
"name": "Coca Cola"
}, {
"group": [1, 3],
"name": "Pizza"
}];
function filter_articles(original_data, group) {
var filtered = original_data.filter(function (item) {
return item.group.indexOf(group) !== -1;
});
var ds = new kendo.data.DataSource({
data: filtered
});
ds.read();
return ds;
}
var filteredDs = filter_articles(original_data, 3);
(demo)