[英]Accordian Table showing all panels when clicked when using Shopify linklists
I have a sidebar menu setup that is looping through shopify linklists and outputting the parent and child collection titles and URLs.我有一个侧边栏菜单设置,它循环遍历 shopify 个链接列表并输出父子集合标题和 URL。 The problem is that when i click on one of the anchor tags, it opens all of the anchor links as the data-target and id are not unique.问题是,当我单击其中一个锚标记时,它会打开所有锚链接,因为数据目标和 ID 不是唯一的。 I have tried changing the div id to a random number using Mat.random() but cant make this work.我尝试使用 Mat.random() 将 div id 更改为随机数,但无法完成这项工作。
Here is the code这是代码
{% for link in linklists[settings.mobile_linklist].links %}
{% if link.links != blank %}
<div class="nav-menu">
<ul id="accordion">
<li class="accordion">
<span><a aria-controls="collapseOne"
aria-expanded="false"
class="collapsible"
data-target="#collapseOne"
data-toggle="collapse"
href="#">{{ link.title }}
</a></span>
<div aria-labelledby="headingOne" class="collapse" id="collapseOne">
<ul>
{% for childlink in link.links %}
<li>
<a href="{{childlink.url}}">{{childlink.title}}</a>
</li>
{% endfor %}
</ul>
</div>
</li>
</ul>
</div>
{% endif %}
{% endfor %}
you can use the forloop.index
to append unique value into a loop in Shopify liquid您可以使用forloop.index
将 append 唯一值放入循环中 Shopify 液体
{% for link in linklists[settings.mobile_linklist].links %}
{% if link.links != blank %}
<div class="nav-menu">
<ul id="accordion-{{forloop.index}}">
<li class="accordion">
<span><a aria-controls="collapseOne"
aria-expanded="false"
class="collapsible"
data-target="#collapse{{forloop.index}}"
data-toggle="collapse"
href="#">{{ link.title }}
</a></span>
<div aria-labelledby="headingOne" class="collapse" id="collapse{{forloop.index}}">
<ul>
{% for childlink in link.links %}
<li>
<a href="{{childlink.url}}">{{childlink.title}}</a>
</li>
{% endfor %}
</ul>
</div>
</li>
</ul>
</div>
{% endif %}
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.