well i already done something like this before hope this helps
<div class="panel-heading" role="tab" id="headingOne" data-bind="foreach: accordionItems()">
<a style="text-decoration:none;" data-toggle="collapse" data-parent="#accordion" aria-expanded="true" aria-controls="collapseOne" data-bind="attr:{href:'#collapseOne'+$index() }" >
<p class="panel-title" data-bind="text: nameHead"></p>
</a> <!--binding a collapse header here.-->
<div class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne" data-bind="attr:{id:'collapseOne'+$index()}">
<ul class="Newsbar panel-body" data-bind="foreach: list">
<li><a data-bind="attr: { href: url }, text: linkText"></a></li>
</ul>
</div>
</div>
Let me explain here :
You just need to create dynamic id
and href
in oder to work with this stuff .
Well lucky you have one loop over if incase there exists multiple loops use $parentContext.index()
and so on .
You just need to use attr
to create dynamic id and href using $index() which gives you unique id everytime it loops .
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…