gpt4 book ai didi

javascript - 如何通过 angularjs $index 分配 href 或 id

转载 作者:太空宇宙 更新时间:2023-11-04 15:38:54 26 4
gpt4 key购买 nike

我尝试使用 bootstrap 和 angularjs 制作可折叠面板。我成功接收了数据,但未能动态放置面板标题的“href”和相关正文的“id”。以下 html 演示了我如何尝试分配“href 和 id”。

HTML

<div class="panel-group"  data-ng-repeat="Art in Articles" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" data-ng-href="go$index"><%-- here is my problem href in runtime not working --%>
{{Art.Art_Title}}
</a>
</h4>
</div>
<div data-ng-id="go$index" class="panel-collapse collapse"> <%-- same problem here with related id --%>

<img data-ng-src="{{Art.Art_Pic}}" style="margin: 20px; border: 4px solid #FFFFFF;
width: 140px; height: 100px; float: left;" />
<div class="panel-body" style="padding: 5px; margin: 5px; text-align: right; background-image: url('../App_Pic/bg03.jpg');">
{{Art.Art_Body}}
</div>
<button type="button" class="btn btn-primary btn-sm " style="margin-bottom: 10px">Read More ...</button>
</div>
</div>
</div>

最佳答案

如果你想在 angularjs 中将字符串和变量组合在引号内,你需要将其设置为 JavaScript 中的有效表达式: 'string'+$variable <div data-ng-id="'go'+$index" class="panel-collapse collapse">

关于javascript - 如何通过 angularjs $index 分配 href 或 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44059531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com