我需要帮助来“使” NG-REPEAT和整个极限“了解”。要了解食品成分ng-show逻辑,我该如何实现?换句话说,我该如何将该逻辑插入ng-repeat和limiter中?
JS端/ HTML端?任何帮助,将不胜感激。谢谢!
这就是我在代码中的意思;
<li
class="xx"
ng-repeat="food in foodlist.$models | filter:search:false | limitTo : foodlength as foodResults track by food.id">
<food
data-food="xxx"
ng-show="(food.$att.random && (search.SomeBoolean || OtherBoolean)) || !food.$att.random"
ui-sref="xx({xx: //irrelvant stuff })"
class="xx-xxxx">
</food>
</li>
答案 0 :(得分:1)
有几种方法可以做到这一点。
您的ng-show
逻辑基本上应该在ng-repeat
内部移动。
IMO最简单的方法是向控制器中的$scope
添加过滤功能,如下所示:
... // Controller creation code
function YourController($scope, ...)
{
... // Controller code
$scope.filterFoodItems = function(food)
{
return (food.$att.random && (search.SomeBoolean || OtherBoolean)) || !food.$att.random;
};
}
下一步是更改filter
中的ng-repeat
值:
<li
class="xx"
ng-repeat="food in foodlist.$models | filter:filterFoodItems | limitTo : foodlength as foodResults track by food.id">
...
</li>
仅出于常识,您还可以编写自定义过滤器,但我认为您的情况没有必要。 就是这样: https://toddmotto.com/everything-about-custom-filters-in-angular-js/