【发布时间】:2021-04-23 23:18:45
【问题描述】:
我正在尝试基于带有复选框的撇号标签构建一个过滤器,以便可以选择多个过滤器(这块已经实现)。我还需要一个按钮来选择所有标签,这是我无法找到答案的地方。如何使用 build 方法向查询添加多个标签?我一直在这里参考 apos 文档。 https://docs.apostrophecms.org/reference/modules/apostrophe-urls.html#methods
当前代码如下。
{# bellow link kind of works but does not allow me to pull the tags once selected #}
<a href="{{ data.url | build({ tags: [data.page.filterTags] }) }}" id="select-all" >Select All</a>
{# bellow code works fine but I thought it might be relevent #}
<br/>
{% for tag in data.page.filterTags %}
{% set current = data.query.affinity == tag %}
{% if apos.utils.contains(data.query.tags, tag) %}
<a href="{{ data.url | build({ tags: { $pull: tag } }) }}" class="current">
<label class="container"><input type="checkbox" name="tag" value="{{item}}" checked="">
{% else %}
<a href="{{ data.url | build({ tags: { $addToSet: tag } }) }}">
<label class="container"><input type="checkbox" name="tag" value="{{item}}">
{% endif %}
<span class="text">{{tag | capitalize}}</span>
<span class="checkmark"></span></label>
</a>
{% endfor %}
【问题讨论】: