2014-07-26 173 views
0

如何使用運算符「in」過濾kendo數據源? 例子:kendo ui數據源過濾器「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) } 
    }); 
} 

回答

1

的數據源過濾選項不支持此功能,所以你必須創建數據源,例如之前篩選數據像這樣:

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