2014-04-23 69 views
0

我怎麼能在NG重複誰是相等的計算元素的變量我怎麼能算元素誰是相等的值NG重複

例如我確實有這個NG-重複,我想指望每元素誰Fund.status是等於「完成」或「待辦事項」:

<tbody ng-repeat="Fund in ListTask| filter:TreeFilter |orderBy:orderByField:reverseSort"> 
         <tr ng-dblclick="open(Fund.id,Fund)" data-toggle="modal" data-target="{{Fund.type}}"> 
          <td>{{Fund.id}}</td> 
          <td>{{Fund.Beneficiary}}</td> 
          <td>{{Fund.Title}}</td> 
          <td>{{Fund.status}}</td> 
          <td>{{Fund.category}}</td> 
          <td>{{FormField.shortDate(Fund.CreationDate)}}</td> 
          <td>{{FormField.shortDate(Fund.DueDate)}}</td> 
          <td>{{Fund.Team}}</td> 
          <td>{{Fund.Officer}}</td> 
         </tr> 
        </tbody> 

回答

0

你可以做到這一點,但它是一個不好的做法。在ng-repeat期間對你視圖中的東西進行計數是令人討厭的。您是遠遠更好做在你的控制器計數和結果暴露的觀點,這樣的

$scope.thoseThatEqualFundOrTodo = function(items){ 
    return _.find(items, function(item){ 
    item.status === 'Todo' || item.status === 'Fund'; 
    }).length; 
}); 

然後在你的模板,你可以這樣做:

<table data-scope-attribute="filteredTasks" data-scope-attribute-watch="ListTask| filter:TreeFilter |orderBy:orderByField:reverseSort"> 

Result: {{thoseThatEqualFundOrTodo(filteredTasks)}} 

<tbody ng-repeat="Fund in filteredTasks"> 
         <tr ng-dblclick="open(Fund.id,Fund)" data-toggle="modal" data-target="{{Fund.type}}"> 
          <td>{{Fund.id}}</td> 
          <td>{{Fund.Beneficiary}}</td> 
          <td>{{Fund.Title}}</td> 
          <td>{{Fund.status}}</td> 
          <td>{{Fund.category}}</td> 
          <td>{{FormField.shortDate(Fund.CreationDate)}}</td> 
          <td>{{FormField.shortDate(Fund.DueDate)}}</td> 
          <td>{{Fund.Team}}</td> 
          <td>{{Fund.Officer}}</td> 
         </tr> 
        </tbody> 
</table> 
+0

它不工作是不是因爲它可以找到物品? – user3542017

+0

我編輯了我的答案。 –

+0

我也試過,但我沒有工作我有一個錯誤,因爲它不知道_.find它說[$ interpolate:interr]無法插入: – user3542017