简体   繁体   中英

filter angularjs doesn't work in my case

I add this into my <li> (line 5) but it returned blank.

| filter: {tabs.tabId: currentTab}

My app demo at http://jsfiddle.net/8Ub6n/8/

my html

 <ul ng-repeat="friend in user">
            <li ng-repeat="relation in friend.relationship">{{relation.name}} ({{relation.points}}points)</li>
        </ul>

here is my js

 $scope.user = [{
        'uId': 1,
            'name': 'Joe',
            'relationship': [{
            'uId': 2,
                'name': 'Jeremy',
                'tabs': [{
                'tabId': 1
            }],
                'tasks': [{
                'name': 'Im Jeremy Lin'
            }],
                'points': 50

        },{
            'uId': 2,
                'name': 'Michael',
                'tabs': [{
                'tabId': 1
            }],
                'tasks': [{
                'name': 'Im Jeremy Lin'
            }],
                'points': 80

        }]
    }]
})

have no idea what's wrong..

Done:

Here it is

Just need to make another function in scope:

$scope.isTab = function (relation) {
   return relation.tab.tabId == $scope.currentTab;
}

then add to the filter:

relation in friend.relationship | filter : isTab

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM