ng-repeat 在两个数组上 [英] ng-repeat on two arrays
问题描述
我想对由两个数组组成的数组执行 ng-repeat,如下所示:
[标题:[],链接:[]]
我的数组(标题和链接)具有相同的长度最后,我想在我的 ng-repeat 中打印的内容是这样的:
{{ array.title }}{{ 数组链接}}
例如,在 C 程序中,我必须这样做:
int i;我 = 0;而(标题[i]){printf("%s - %s", titles[i], links[i]);我++;}
不清楚您是如何获得数据的 — [titles: [], links: []]
没有意义.
理想情况下,您将数据排列为如下所示的对象数组:
var array = [{title: "foo", link: "bar"}, {title...etc]
然后你可以使用:
{{obj.title}}, {{obj.link}}如果您知道标题和链接的大小总是相同的,您可以这样做,但它不是很漂亮,而且可能有点脆弱:
{{title}}, {{links[$index]}}
I want to do a ng-repeat on an array which is composed of two arrays, like this :
[titles: [], links: []]
My arrays (titles and links) have the same length
What i want to print in my ng-repeat, finally, is anything like that :
{{ array.title }}
{{ array.link }}
For example, in a C program i have to do that :
int i;
i = 0;
while (titles[i])
{
printf("%s - %s", titles[i], links[i]);
i++;
}
解决方案 It's not clear how you have your data — [titles: [], links: []]
isn't meaningful.
Ideally you would arrange your data as an array of objects that looks like:
var array = [{title: "foo", link: "bar"}, {title…etc]
Then you could just use:
<div ng-repeat="obj in array">
{{obj.title}}, {{obj.link}}
If you know that titles and links will always be the same size you can do this, but it's not very pretty and might be a little fragile:
<div ng-repeat="title in titles">
{{title}}, {{links[$index]}}
</div>
这篇关于ng-repeat 在两个数组上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文