gpt4 book ai didi

javascript - Angular ng-repeat 导致 NaN

转载 作者:行者123 更新时间:2023-11-28 18:44:47 26 4
gpt4 key购买 nike

我正在使用 ng-repeat 循环访问 API 的内容,但我遇到了名称中带有斜杠的项目的问题。例如,这有效:

    <ul ng-controller="StandingsCtrl" class="list-inline">
<div ng-repeat="standing in standings.results">
<li><h3>{{ standing.musher }}</h3></li>
</div>
</ul>

但是如果我使用 {{standing.musher/_text }} 它会返回 NaN。 JSON 如下所示:

musher: "http://iditarod.com/race/2015/mushers/92-Mitch-Seavey/"
musher/_text: "Mitch Seavey"
position: 2

这里面有什么技巧吗?我根本没有收到任何控制台错误。使用 Angular 1,而不是 2。

最佳答案

使用此表示法{{standing['musher/_text'] }}:

<ul ng-controller="StandingsCtrl" class="list-inline">
<div ng-repeat="standing in standings.results">
<li><h3>{{ standing['musher/_text'] }}</h3></li>
</div>
</ul>

当使用 {{standing.musher/_text }} 时,Angular 会将其计算为除法:"http://iditarod.com/race/2015/mushers/92-Mitch- Seavey/"/undefined,结果为 NaN

关于javascript - Angular ng-repeat 导致 NaN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35556681/

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