0

如何使用运算符“in”过滤剑道数据源?例子:

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) }
    });
}
4

1 回答 1

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);

演示

于 2014-07-26T17:16:33.307 回答