2014-04-15 21 views
0

我將此添加到我的<li>(第5行),但它返回空白。filter angularjs在我的情況下不起作用

| filter: {tabs.tabId: currentTab} 

http://jsfiddle.net/8Ub6n/8/

我的HTML

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

這裏是我的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 

     }] 
    }] 
}) 

不知道什麼是錯的我的應用程序演示..

+0

你還沒有包括在你擺弄的過濾器?事實上,在你的小提琴中沒有任何與標籤有關的東西。也許嘗試和解釋多一點,你試圖實現什麼 –

+0

如果我包括它,它會給一個空白的小提琴 – noob

+0

@ No1_Melman編輯 – noob

回答

1

完成:

Here it is

只需要再拍功能範圍:

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

然後添加到過濾器:

relation in friend.relationship | filter : isTab 
+0

這是幹什麼用的? VAR應用= angular.module( '對myApp',[])濾波器( '標籤',函數(){ 回報功能(輸入,currentTab){ 返回輸入== currentTab; }; })。 – noob

+0

@noob忽略這一點,這是一個考驗。它什麼都不做;) –

+0

@noob它可以工作,如果你改變'currentTab'並點擊Run :) –

相關問題