【发布时间】:2018-07-16 16:58:17
【问题描述】:
我正在尝试找到将两个数组连接在一起的最佳方法,我猜想是嵌套的 ng-repeat。这是我可用的数据(非常简短的示例);
GameGenre Table
ID | Genre
1 | Action
2 | First Person Shooter
3 | Adventure
Game Table
ID | IDGenre | Name
1 | 1 | SpiderMan
2 | 1 | Batman
3 | 2 | Wolfenstein
4 | 3 | Just Cause
5 | 3 | Tomb Raider
6 | 3 | Indiana jones
所以我正在寻找将两个数组组合在一起的最佳方式(一种方式/禁食方式),所以我把它弄出来
IDGameGenre 1 Holds: GAMEID1 and GameID2
IDGameGenre 2 Holds: GameID3
IDGameGenre 3 Holds: GameID4, GameID5, GAMEID6
这是我目前想出的,我首先消耗两个数组:
在控制器中:
$http({
method: 'Get',
url: http://URL/api/GameGenre/All"
})
.success(function (data) {
$scope.GameGenre= data;
});
$http({
method: 'Get',
url: http://URL/api/Game/All"
})
.success(function (data) {
$scope.Game= data;
});
$scope.getTheGame = function(ID) {
return Game.get({IDGenre: ID});
};
在 HTML 中
<div class="listing" ng-repeat="Genre in GameGenre" ng-init='getTheGame(Genre.ID)'>
<div class="Game" ng-repeat="Game in getTheGame"></div>
</div>
但我似乎无法完成这两项工作,我如何能够首先使用这两个数组,将它们都添加到范围,然后对信息进行排序。
【问题讨论】:
-
为什么不在后端添加该功能?在您的 GameGenre 类中,添加一个游戏列表,然后在该列表中添加所有反对该类型的游戏。使用这种方法,您也不必对后端进行两次单独的调用
-
不幸的是我不能
标签: arrays angularjs angularjs-ng-repeat