【发布时间】:2020-06-28 13:30:52
【问题描述】:
我只有一个显示标题、描述和类别的数组。
由于我不知道类别(因为用户可以添加自己的类别),所以我使用 ng-repeat 做了类别列表,同样显示项目。
而且我需要能够使用两个过滤器过滤的项目:使用按标题过滤的文本输入(这个非常好用)和类别按钮(不起作用)。
以下是我对类别进行 ng-repeat 的方式:
<div class="list_categories">
<!-- I put 'ng-repeat-start' and 'ng-repeat-end' to be able to add the value "checked" to the first input -->
<!-- it wasn't working and @tbone849 already helped me with that-->
<label ng-click="clearAll()" ng-repeat-start="x in categories" ng-if="$first">
<input type="radio" id="optradio" name="optradio" ng-model="searchCategory.Category" value="{{x}}" checked="checked">
<p>{{x}}</p>
</label>
<label ng-click="clearAll()" ng-repeat-end ng-if="!$first">
<input type="radio" id="optradio" name="optradio" ng-model="searchCategory.Category" value="{{x}}">
<p>{{x}}</p>
</label>
</div>
这是项目的 ng-repeat:
<div class="card" ng-repeat="x in items | filter:searcher | filter:searchCategory" >
<div class="title-space">
<h2>{{x.Title}}</h2>
</div>
<div class="description-space">
<p>{{x.Description}}</p>
</div>
</div>
有关我的代码的更多详细信息,我在 this Plunker 中做了一个工作示例。
我希望有人可以帮助我使类别过滤器起作用。
【问题讨论】:
标签: javascript angularjs angularjs-ng-repeat angularjs-filter