我有一系列物品。其中一些项目是某些其他“父项”的“子项”。我没有从服务器重新安排JSON,而是试图在ng-repeat循环中过滤结果。每个项目都有一个id和一个“father_id”属性。如果此属性的值为0,则表示它是父元素。问题是,我没有设法过滤内部循环,它依赖于父循环中的某些值。
这就是我在父循环中所拥有的,它可以正常工作:
ng-repeat="fatherEvent in pageInitialAjaxContent | filter:{father_id:0}"
这将显示“father_id”为0的所有元素,这意味着它们没有父元素,这使得父元素成为父元素。
在内循环中,我试过这个,但没有成功:
ng-repeat="ChildEvent in pageInitialAjaxContent | filter:{father_id:fatherEvent.id}"
这是为了过滤项目,其父ID对应父项的ID。它给了我奇怪的意外结果。
有人可以告诉我构建这个表达式的正确方法是什么?
答案 0 :(得分:1)
I think you need to restructure the second ng-repeat like so
ng-repeat="ChildEvent in pageInitialAjaxContent | filter:{father_id:fatherEvent.id}:true"
The :true
checks for an exact match whereas the default, :false
, checks for a substring match.
Check out the comparator
argument in the docs here