我已经为这件事挣扎了一段时间,它似乎“如此简单”,但我完全无法理解。
我有一个来自维基百科的$http.get,它返回如下JSON:
[[
"Foobar",
"Foobar2000",
"Foobar (disambiguation)",
"Foxbar",
"Foodarama",
"Fobar",
"Foodar",
"Foxbar railway station",
"Fox Barrel",
"Fox baronets"
],
[
"The terms foobar (/ˈfuːbɑːr/), fubar, or foo, bar, baz and qux (alternatively, quux) and sometimes norf and many others are sometimes used as placeholder names (also referred to as metasyntactic variables) in computer programming or computer-related documentation.",
"foobar2000 is a freeware audio player for Microsoft Windows developed by Piotr Pawlowski, a former freelance contractor for Nullsoft.",
"",
"Foxbar is an area of Paisley, bordered by the Gleniffer Braes and Paisley town centre. Consisting mostly of residential areas, Foxbar has rapidly grown over the past century to be one of the largest housing areas in the town.",
"Foodarama, also known as Cox's Foodarama, is a supermarket chain in Texas, with its headquarters in Foodarama Store #1 in Brays Oaks, Houston.",
"Fobar is a Malagasy football club based in Toliara, Madagascar.",
"",
"",
"Fox Barrel is a brand of perry (marketed as \"pear cider\") made in Colfax, CA.",
"The Fox Baronetcy, of Liverpool in the County Palatine of Lancaster, was a title in the Baronetage of the United Kingdom."
],
[
"https://en.wikipedia.org/wiki/Foobar",
"https://en.wikipedia.org/wiki/Foobar2000",
"https://en.wikipedia.org/wiki/Foobar_(disambiguation)",
"https://en.wikipedia.org/wiki/Foxbar",
"https://en.wikipedia.org/wiki/Foodarama",
"https://en.wikipedia.org/wiki/Fobar",
"https://en.wikipedia.org/wiki/Foodar",
"https://en.wikipedia.org/wiki/Foxbar_railway_station",
"https://en.wikipedia.org/wiki/Fox_Barrel",
"https://en.wikipedia.org/wiki/Fox_baronets"
]]我在挣扎的是我的重复,现在是:
<div ng-repeat="array in wikiSearch">
<div ng-repeat="x in array">
{{x}}
</div>
</div>
我最终得到的是数组1,然后数组2,然后数组3的列表,我想要的是值0,从数组1,2,3,然后值1,数组1,2,3等等.
发布于 2016-03-17 05:56:54
我认为这就是你们正在努力实现的目标:
<div ng-repeat="array in wikiSearch[0]">
<div ng-repeat="x in wikiSearch">
{{wikiSearch[$index][$parent.$index]}}
</div>
</div>请检查并‘运行’我的代码在柱塞:http://plnkr.co/edit/GpNStIwu2roY4ho9qlhr?p=preview。
其结果将是:
福巴
在计算机编程或计算机相关文档中,foobar (/ˈfuːbɑːr/)、fubar或foo、bar、baz和qux (或者,quux)以及norf和许多其他术语有时用作占位符名称(也称为元异步变量)。
https://en.wikipedia.org/wiki/Foobar
Foobar2000
foobar2000是由Pawlowski开发的微软Windows的免费音频播放器,他曾是Nullsoft的自由职业者。
发布于 2016-03-17 01:26:18
唯一明智的做法是在收到来自$http.get的响应后创建一个新的重新格式化的数组。例如:
$scope.myArray = [];
$http.get("http://someurl.com/api/items").then(function(response){
for( i=0; i<response.data[0].length; i++){
$scope.myArray.push({
title: response.data[0][i],
description: response.data[1][i],
url: response.data[2][i]
});
}
});通常它被称为“压缩”数组(如果您希望搜索更复杂的内容):Javascript等价于Python的zip函数
发布于 2016-03-17 01:31:53
试试这个:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
</head>
<body>
<div id="app" ng-app="app" ng-controller="ctrl">
<div ng-repeat="x in wikiSearch" ng-init="i = $index">
<div ng-repeat="y in wikiSearch[i]">
{{ wikiSearch[i][$index] }}
</div>
</div>
</div>
<script src="./controller.js"></script>
</body>
</html>我在控制器中的变量$wikiSearch中复制并粘贴了上面的JSON。
这是一个JSFiddle
https://stackoverflow.com/questions/36049929
复制相似问题