【发布时间】:2016-08-30 05:44:10
【问题描述】:
我为我的 ng-table 实现了一个自定义过滤器,它使用 ngTagInput。 Link[1] 与我的代码类似,此过滤器仅适用于当前页面。 获取所有结果以在 ng-repeat 中过滤的正确方法是什么。
过滤器的代码 sn-p:
.filter('filterByTags', function () {
return function (items, tags) {
var i = 0;
var filtered = []; // Put here only items that match
(items || []).forEach(function (item) { // Check each item
var matches = tags.some(function (tag) { // If there is some tag
i++;
return (item.name.indexOf(tag.name) > -1) // that is a substring
}); // we have a match
if (matches) { // If it matches
filtered.push(item); // put it into the `filtered` array
}
});
if(i == 0){
return items;
}
else{
return filtered;
}
};
})
【问题讨论】:
标签: javascript angularjs angularjs-ng-repeat ngtable