【问题标题】:Apostrophe cms create a 'select all' button for filtering tags撇号 cms 创建用于过滤标签的“全选”按钮
【发布时间】: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 %}

【问题讨论】:

    标签: apostrophe-cms nunjucks


    【解决方案1】:

    我已经回答了我自己的问题,以防有人遇到同样的问题。您应该能够设置标签,而无需在数组周围放置方括号(见下文)。

    <a href="{{  data.url | build({ tags: data.page.filterTags }) }}" id="select-all" >Select All</a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多