在两个数组NG-重复 [英] ng-repeat on two arrays
问题描述
我想做一个NG重复它由两个数组的数组上,像这样的:
[标题:[],链接:[]
我的阵列(标题和链接)具有相同的长度
我想在我的NG-重复打印什么,最后,是这样的事情:
{{array.title}}
{{array.link}}
例如,在C程序我必须做的是:
INT I;I = 0;
而(标题[I])
{
的printf(%S - %的,标题[I]中,链接[I]);
我++;
}
目前还不清楚,你怎么会有你的数据 - [标题:[],链接:[]
是没有意义的。
理想情况下你会安排您的数据对象的数组,看起来像:
VAR阵列= [{标题:富,链接:酒吧},{标题...等]
然后,你可以只使用:
< DIV NG重复=OBJ数组>
{{obj.title}},{{obj.link}}
如果您了解的标题和链接将永远是你可以做到这一点的大小相同,但它不是很pretty和可能有点脆弱的:
< DIV NG重复=称号,称号>
的{{title}},{{链接[$指数]}}
< / DIV>
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-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!