AngularJS NG-重复:如何对象的属性阵列上重复而迭代对象数组
问题描述:
我有一个特别的问题:AngularJS NG-重复:如何对象的属性阵列上重复而迭代对象数组
我有了这个对象在我的范围数组:
Object[0] {
configured: true,
configuration: {
Object[0] {
qty1: 1,
qty2: 2
}
Object[1] {
qty1: 3,
qty2: 4
}
}
},
Object[1] {
configured: true,
configuration: {
Object[0] {
qty1: 5,
qty2: 6
}
Object[1] {
qty1: 7,
qty2: 8
}
}
}
现在,我正在使用ng-repeat指令来显示表格中的对象,但我需要在每个td中显示qty值。结果必须是这样的:
<tr>
<td>1</td>
<td>2</td>
<tr>
<tr>
<td>3</td>
<td>4</td>
<tr>
<tr>
<td>5</td>
<td>6</td>
<tr>
我不知道是否有没有这样做只用角指令(不使用填充数量值的临时数组)的方法吗?
非常感谢, 祝你有美好的一天! :)
答
在内部对象只是想迭代
controller.js
$scope.getValues = function(configuration) {
var values = [];
configuration.forEach(function(c) {
values = values.concat(Object.values(c));
});
return values
}
模板
<tr ng-repeat="x in array| filter: {configured: true}">
<td ng-repeat="val in getValues(x.configuration)" ng-bind="::val"></td>
</tr>
bugs_cena嗨, 非常感谢你的回答。好吧,哇,所以我可以嵌套重复... 而如果我想这样的结果呢? 这不能用ng-repeat嵌套来实现,对吧?
是的,你不能使用嵌套的重复 - 也可能不需要。你只需要创建一个变量来保存需要渲染的扁平值。
清除!谢谢你,朋友! – GermaN