0
我試圖通過標籤網格篩選項目,在網格中的數據看起來像這樣劍道的UI電網濾波
[
{ id: 0, tags: [{ text: 'boat' }, { text: 'summer' }] },
{ id: 1, tags: [{ text: 'boat' }] },
{ id: 2, tags: [{ text: 'travel' }] },
{ id: 3, tags: [{ text: 'boat' }] },
{ id: 4, tags: [{ text: 'travel' }] },
{ id: 5, tags: [{ text: 'travel' }, { text: 'summer' }] }
]
和過濾功能看起來像這樣
$scope.filterGrid = function (e) {
var grid = $('#imageGrid').data('kendoGrid');
var val = [{ text: 'travel' }, { text: 'summer' }];
grid.dataSource.filter({});
if ($.trim(val) !== '') {
grid.dataSource.filter({
logic: 'or',
filters: [{
field: 'tags',
operator: function (item) {
var status = false;
for (var n = 0, length2 = val.length; n < length2; n++) {
for (var i = 0, length = item.length; i < length; i++) {
if (item[i].text.indexOf(val[n].text) !== -1) {
status = true;
break;
}
}
}
return status;
}
}]
});
}
};
在這個例子中,val = travel,夏天我只想顯示兩個標籤(id 5)的項目,但它顯示包含任一標籤的所有項目(id:0,2,4,5)
什麼我做錯了,有沒有更好的辦法用劍道做這個?