单个元素上的多个 ng-repeat [英] Multiple ng-repeat on single element
本文介绍了单个元素上的多个 ng-repeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是否可以实现这样的代码:-
Is this possible to achieve a code like this:-
<tr ng-repeat="data in dataArray,value in valueArray">
{{data}} {{value}}
</tr>
我有两个数组,我想在一行中显示它们.
PS:我不是要求语法.我正在寻找实现这一目标的逻辑
I am having two arrays I want to show them in single row.
PS: I am not asking for syntax. I am looking for logic to achieve this
谢谢
喜欢:- "http://jsfiddle.net/6ob5bkcx/1/"">
推荐答案
您应该在控制器中执行此操作,而不是在视图中.将 dataValues 映射到键/值对对象并使用索引引用值数组.这假设每个数据键都有一个对应的值键.
You should be doing this in the controller, not in the view. Map the dataValues into a key/value pair object and reference the values array using an index. This assumes that each data key has a corresponding value key.
控制器:
var dataArray = [];
var valueArray = [];
this.repeatData = dataArray.map(function(value, index) {
return {
data: value,
value: valueArray[index]
}
});
查看:
<tr ng-repeat="data in repeatData">
{{data.data}} {{data.value}}
</tr>
这篇关于单个元素上的多个 ng-repeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文