Javascript 如何在AngularJS中处理循环中的if语句?

Javascript 如何在AngularJS中处理循环中的if语句?,javascript,angularjs,if-statement,Javascript,Angularjs,If Statement,我有两个循环 <ion-list> <ion-item ng-repeat="category in categories" href="#"> {{category.name}} {{category.id}} <ion-item ng-repeat="test in tests" href="#"> {{test.name}} {{test.cat_id}}

我有两个循环

    <ion-list>
      <ion-item ng-repeat="category in categories" href="#">
        {{category.name}} {{category.id}}
          <ion-item ng-repeat="test in tests" href="#">
              {{test.name}} {{test.cat_id}}
          </ion-item>
      </ion-item>
    </ion-list>

{{category.name}{{category.id}
{{test.name}{{test.cat_id}
我想测试
if(category.id==test.cat\u id)
然后显示第二个列表

我不确定是否以及如何使用
ngif
,或者我是否应该在控制器中处理此问题,并返回一个已格式化的对象以满足我的需要


有什么想法吗

像这样的东西怎么样

<ion-list>
  <ion-item ng-repeat="category in categories" href="#">
    {{category.name}} {{category.id}}
      <ion-item ng-repeat="test in tests | filter:{cat_id: category.id}" href="#">
          {{test.name}} {{test.cat_id}}
      </ion-item>
  </ion-item>
</ion-list>

{{category.name}{{category.id}
{{test.name}{{test.cat_id}

如果我理解正确,您希望有条件地显示第二个ng重复。如果是这种情况,那么您可以使用:

<ion-list>
  <ion-item ng-repeat="category in categories" href="#">
    {{category.name}} {{category.id}}
      <ion-item ng-repeat="test in tests" href="#" ng-if="category.id === test.cat_id">
          {{test.name}} {{test.cat_id}}
      </ion-item>
  </ion-item>
</ion-list>

{{category.name}{{category.id}
{{test.name}{{test.cat_id}
另一种选择是使用如下过滤器:

<ion-list>
  <ion-item ng-repeat="category in categories" href="#">
    {{category.name}} {{category.id}}
      <ion-item ng-repeat="test in tests | filter: {cat_id: category.id}" href="#" ng-if="category.id === test.cat_id">
          {{test.name}} {{test.cat_id}}
      </ion-item>
  </ion-item>
</ion-list>

{{category.name}{{category.id}
{{test.name}{{test.cat_id}
实际上,我会推荐过滤器选项。

也许吧?