我正在使用AngularJS。如何按Code
进行搜索?我当前的实现搜索你输入的内容:id,name,city,code ...我如何只搜索代码?
app.js:
var app = angular.module('stack', []);
app.directive('filterList', function ($timeout) {
return {
link: function (scope, element, attrs) {
var td = Array.prototype.slice.call(element[0].children);
function filterBy(value) {
td.forEach(function (el) {
el.className = el.textContent.toLowerCase().indexOf(value.toLowerCase()) !== -1 ? '' : 'ng-hide';
});
}
scope.$watch(attrs.filterList, function (newVal, oldVal) {
if (newVal !== oldVal) {
filterBy(newVal);
}
});
}
};
});
示例jSFiddle
答案 0 :(得分:3)
String[] names = line.split(",");
答案 1 :(得分:1)
如果你有任何文本框来编写代码并根据它进行过滤,那么你可以使用|像这样的角度内置过滤器,
<div ng-repeat="product in products | filter:{ colour: by_colour }">
希望这有助于解决您的问题:)