我在过滤方面遇到了一些问题。我做了几个按钮:
<button ng-click="myFilter = {terms: advertising}">Advertising</button>
<button ng-click="myFilter = {terms: branding}">Branding</button>
<button ng-click="myFilter = {terms: packaging}">Packaging</button>
<button ng-click="myFilter = {terms: print}">Print</button>
我当然有阵列:
$scope.selects = [
{terms: 'Advertising | Web',},
{terms: 'Branding | Packaging',},
{terms: 'Print | Video',},
{terms: 'Branding | Print',}
];
因为你可以看到我在一个键中得到的条款很少。我知道我可以使用搜索框进行过滤,它可以正常工作。但我已经为此使用了按钮。
此方法:
<article class="select_single" dir-paginate="select in selects | itemsPerPage: pageSize | orderBy:sortorder | filter:myFilter" current-page="currentPage">
只有在我使用相同的字符串时才有效,但是我需要过滤与它们类似的项目。
我尝试创建隐藏输入,然后将按钮id发送到输入值,但是我需要对此输入进行任何更改以运行过滤器。
其余代码:
<div ng-controller="MyController" class="my-controller">
<div id="loop">
<article class="select_single" dir-paginate="select in selects | itemsPerPage: pageSize | orderBy:sortorder | filter:myFilter" current-page="currentPage">
<img src="{{ select.img }}">
<div class="overlay">
<div class="text">
<h3>{{ select.name }}</h3>
<p class="terms">{{ select.terms }} </p>
<a href="{{ select.link }}">More Details</a>
</div>
</div>
</article>
</div>
<div class="sort_handle">
<div ng-controller="OtherController" class="other-controller pull-right">
<div class="text-center">
<dir-pagination-controls boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="<?php echo get_template_directory_uri(); ?>/templates/pagination.tpl.html"></dir-pagination-controls>
</div>
</div>
</div>
</div>
所以..
我的问题是如何使用数组键字符串的一部分来过滤这些术语?
Grettings,W
答案 0 :(得分:2)
这应该是相当简单的,因为您的过滤器正确使用了它要过滤的正确结构。
错误是您的搜索过滤器应包含myFilter.terms
的字符串(请注意引号):
<button ng-click="myFilter = {terms: 'advertising'}">Advertising</button>
<button ng-click="myFilter = {terms: 'branding'}">Branding</button>
<button ng-click="myFilter = {terms: 'packaging'}">Packaging</button>
<button ng-click="myFilter = {terms: 'print'}">Print</button>
然后过滤是:
<div ng-repeat="select in selects | filter: myFilter">
{{select}}
</div>