在两个数组NG-重复 [英] ng-repeat on two arrays

查看:121
本文介绍了在两个数组NG-重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个NG重复它由两个数组的数组上,像这样的:

  [标题:[],链接:[]

我的阵列(标题和链接)具有相同的长度
我想在我的NG-重复打印什么,最后,是这样的事情:

  {{array.title}}
{{array.link}}

例如,在C程序我必须做的是:

  INT I;I = 0;
而(标题[I])
{
    的printf(%S - %的,标题[I]中,链接[I]);
    我++;
}


解决方案

目前还不清楚,你怎么会有你的数据 - [标题:[],链接:[] 是没有意义的。

理想情况下你会安排您的数据对象的数组,看起来像:

  VAR阵列= [{标题:富,链接:酒吧},{标题...等]

然后,你可以只使用:

 < D​​IV NG重复=OBJ数组>
   {{obj.title}},{{obj.link}}

如果您了解的标题和链接将永远是你可以做到这一点的大小相同,但它不是很pretty和可能有点脆弱的:

 < D​​IV 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆