gpt4 book ai didi

javascript - 过滤特定的多个表达式 Angular js

转载 作者:行者123 更新时间:2023-11-28 06:24:42 25 4
gpt4 key购买 nike

我只想在列名称或数字中搜索,目前我仅在列名称中搜索。

<input type="text" ng-model="test.name" placeholder="start typing..">

我的表情

  <tr ng-repeat="x in names | filter:test | limitTo:totalDisplayed">
<td>{{ x.name }}</td>
<td>{{ x.number}}</td>
<td>{{ x.city }}</td>
<td>{{ x.country }}</td>
</tr>

最佳答案

创建自定义过滤器来完成此操作。

html

<input type="text" ng-model="test.name" placeholder="start typing..">
<tr ng-repeat="x in names | myFilter: test">
<td>{{ x.name }}</td>
<td>{{ x.number}}</td>
<td>{{ x.city }}</td>
<td>{{ x.country }}</td>
</tr>

js过滤器

angular.module('myApp').filter('myFilter', function () {
return function (list, input) {

//input is test object and list is your current array you want to return a filtered array
var myArray = [];
list.forEach(function(o, i){
if(o.name.indexOf(input.name) > -1 || o.number.indexOf(input.name) > -1 )
myArray.push(o);
});

return myArray
};
});

关于javascript - 过滤特定的多个表达式 Angular js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35233000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com