簡體   English   中英

AngularJS-過濾特定的深色屬性

[英]AngularJS - filter on a specific deep property

我有一個javascript對象,想在特定的深色屬性上使用angular的過濾器,但它似乎不起作用。

function MyCtrl($scope, $filter)
{
 $scope.items = [
    {id:{val:1,str:'abc'}, name:'John'},
    {id:{val:2,str:'abcd'}, name:'John'},
    {id:{val:3,str:'xyz'}, name:'John'},
    {id:{val:4,str:'axcvb'}, name:'John'},
    {id:{val:5,str:'qwe'}, name:'John'}];

 $scope.items2 = $scope.items;

 $scope.$watch('search', function(param)
 {
    $scope.items = $filter('filter')($scope.items2, {id:{val:param}},false);
 });
};

這是小提琴http://jsfiddle.net/Lhhetazm/2/

如果我只是說,

$scope.items = $filter('filter')($scope.items2, {id:param},false);

然后它起作用了,但是它搜索了不是我想要的整個對象,並且我希望它可以用於部分搜索,因此我將完全匹配標志設置為false

從Controller擺脫$watch並在ng-repeat上執行過濾器...

<tr ng-repeat="item in items | filter:{id.val:search}">
    <td>{{item.id}}</td>
    <td>{{item.name}}</td>
</tr>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM