2013-07-15 2 views
0

내가하고 싶은 것은 리피터 범위를 기반으로 특정 속성에 의해 객체 배열의 필터 길이를 계산하는 것입니다. 스코프 ID, 그것 1, 10, 11, 21 등 I에 일치하는 (예를 들어) 1AngularJS 필터 길이와 정확한 값

<li ng-repeat="question in questions" id="{{ question.id }}"> 
    {{ question.text }} 
    <ul> 
     <li ng-repeat="answer in question.answers" id="{{ answer.id }}"> 
      {{ answer.text }} (<span ng-controller='AnswersController'>{{ (useranswers|filter:{answer_id:answer.id}).length }}</span>) 
     </li> 
    </ul> 
</li> 

문제는,이 코드는 기술적 (이 필터의 정확한 수를 표시) 작동 위의 정확한 코드를 정확하게 일치시켜야합니다.

어떤 지원 코드가 도움이되는지 알려주십시오.

+0

여기에 비교 코드가 있습니까? 나는 뭔가를 놓치고 있을지도 모르겠지만 아마도 x.indexOf (y) == - 1 또는 x == y 또는 x === y와 비슷한 것을 말할 수는 없다. – shaunhusain

답변

8

엄격한 비교를 원한다는 것을 Angular에게 말해야합니다. 필터 filter (documentation 참조)이 comparator 인 세 번째 매개 변수를 가지므로 Angular 1.1.5로하기 쉽습니다. true은 매우 유용한 속기입니다. 귀하의 경우 다음과 같이 간단하게 만들 수 있습니다 :

<li ng-repeat="question in questions" id="{{ question.id }}"> 
    {{ question.text }} 
    <ul> 
     <li ng-repeat="answer in question.answers" id="{{ answer.id }}"> 
      {{ answer.text }} (<span ng-controller='AnswersController'>{{ (useranswers|filter:{answer_id:answer.id}:true).length }}</span>) 
     </li> 
    </ul> 
</li> 
+0

완벽한 답변. 감사. –