【发布时间】:2016-12-23 19:25:23
【问题描述】:
如果有人问过类似的问题,请原谅我。我正在使用 Angular JS 1.5 制作一个网络应用程序。
在下面显示的控制器中,我请求了一个 JSON 对象数组并将它们存储在 $scope.gameList 中。对于上下文,我有一个 JSON 文件,其中包含存储为对象数组的 Steam 商店中的游戏列表。然后,我使用此代码通读,如果名称匹配,则将其添加到名为 cleanGameNames 的数组中,然后将其存储在 $scope.cleanedGameNames 中。 Data 是一个 JSON 对象数组,其中包含来自 IGDB API 的搜索结果列表。
if(data[i]["name"].replace(": ", " - ") === $scope.gameList[j]["name"]){
console.log("replaces colon trailing space with dash");
cleanedGameNames[i] = $scope.gameList[j]["name"];
console.log(cleanedGameNames[i]);
}
在我的 HTML 中,我正在循环访问 $scope.gameList(一个包含所有 Steam 游戏的数组)和 $scope.games(一个包含来自 IGDB API 的搜索结果列表的数组)。
<ul ng-repeat="steam in gameList | filter:game.name:true " ng-show="$first">
<div ng-repeat="gameName in cleanedGameNames track by $index">
<li>
<div ng-show="gameName == steam.name">
<p ng-bind="steam.name">{{steam.name}}</p>
<a ng-href="http://store.steampowered.com/app/{{steam.appid}}">Buy on steam</a>
</div>
</li>
</div>
</ul>
我期望它在我的表格单元格中显示的是
Warlock - Master of the Arcane (this was originally Warlock: Master of the Arcane but I did a replace on this string and stored the result of the replace function in an element of my cleanedGameNames array.
Buy on Steam //This would be a link to buy the game on the steam store
相反,当我尝试在表格中显示此字符串时,我什么也得不到。这一切都显示在 HTML 表格中。在我的 angular.js 文件中,我已经完成了一些 console.log 语句,似乎术士 - 奥术大师正按预期发送到 $scope.cleanedGameNames(我在我的 HTML 代码中循环的数组)。
有什么我遗漏的吗?
【问题讨论】:
标签: javascript angularjs arrays json