我想用 3 个数组来填充表格。我希望这些值位于不同的列中,含义:
Column1(People)| Column2(Animals)| Column3(Letters)|
----- | ----- | ----- |
----- | ----- | ----- |
----- | ----- | ----- |
----- | ----- | ----- |
好吧,我可以制作 3 张 table 并将它们并排放置,但我想知道我是否可以这样做。
如您所见, fiddle 的结果很丑陋。
最佳答案
如果您确实没有选择在不同的数组中处理数据,您可以使用 $index 来实现这一点。 (从未测试过数组具有不同长度):
<tr ng-repeat="person in people">
<td>{{ people[$index].first + ' ' + people[$index].last }}</td>
<td>{{ animals[$index].first + ' ' + animals[$index].last }}</td>
<td>{{ letters[$index].first + ' ' + letters[$index].last }}</td>
</tr>
或者您可以获得更大的数组长度,如下所示:
<tr ng-repeat="i in getMaxLength()">...
在你的 Controller 中的某个地方:
$scope.getMaxLength = function() {
//....
return max;
}
在其他地方,您可以按照 @Daniel 建议在同一个数组中处理它们。这取决于您的数据如何..
关于javascript - Angularjs - 同一个表中不同列的多个 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34531041/