必要なパラメータを持つカスタムフィルタを作成します。
app.filter('myFilter', function(){
// Just add arguments to your HTML separated by :
// And add them as parameters here, for example:
// return function(dataArray, searchTerm, argumentTwo, argumentThree) {
return function(dataArray, searchTerm) {
// If no array is given, exit.
if (!dataArray) {
return;
}
// If no search term exists, return the array unfiltered.
else if (!searchTerm) {
return dataArray;
}
// Otherwise, continue.
else {
// Convert filter text to lower case.
var term = searchTerm.toLowerCase();
// Return the array and filter it by looking for any occurrences of the search term in each items id or name.
return dataArray.filter(function(item){
var termInId = item.id.toLowerCase().indexOf(term) > -1;
var termInName = item.name.toLowerCase().indexOf(term) > -1;
return termInId || termInName;
});
}
}
});
次にHTML
<tr ng-repeat="item in data | myTableFilter:filterText:argumentTwo:argumentThree">
にfilter-by-multiple-columns-with-ng-repeat
私はこれを試してみましょう! – user1732364
これがうまくいった!ありがとうございます – user1732364