Angularjs &引用;包括「;搜索对象数组的子元素
以下是我的数据:Angularjs &引用;包括「;搜索对象数组的子元素,angularjs,Angularjs,以下是我的数据: [ {profile: {name: "Test123"}} ] 我有一个文本输入,如下所示: <input ng-model="searchText"> $scope.searchFilter = function(value){ return value.profile.name.indexOf($scope.searchText) != -1; }; 然后像这样过滤: <tr ng-repeat="profile in profil
[
{profile: {name: "Test123"}}
]
我有一个文本输入,如下所示:
<input ng-model="searchText">
$scope.searchFilter = function(value){
return value.profile.name.indexOf($scope.searchText) != -1;
};
然后像这样过滤:
<tr ng-repeat="profile in profiles | filter: searchFilter"></tr>
不幸的是,这在最初的搜索中似乎效果很好,但在文本框中输入文本时,不会重新计算过滤器
当我在搜索框中输入文本时,如何强制Angular重新检查过滤器,或者是否有更好的方法来执行此操作?您不需要创建搜索函数。只需将您的html更改为:
<input ng-model="searchText.profile.name" />
...
<tr ng-repeat="data in profiles | filter: searchText">{{data.profile.name}}</tr>
然后它就起作用了。:)
$scope.searchText = { profile: {name:""}}; //should be the same data struct with your search target.
$scope.profiles = [
{profile: {name: "Someone"}},
{profile: {name: "Luky"}},
{profile: {name: "John"}},
{profile: {name: "Mary"}},
{profile: {name: "Howard"}},
{profile: {name: "Sheldon"}}
]