【发布时间】:2015-03-19 09:35:24
【问题描述】:
提前感谢您的阅读。我正在尝试利用 Angular 的 ng-repeat 将数组中的对象渲染到 Nx3 表中。为了举例,让我们考虑一个 3x3 的表格。
这里是一个简化的数组示例:
objects = [{"text": "One, One"},{"text": "One, Two"},{"text": "One, Three"},
{"text": "Two, One"},{"text": "Two, Two"},{"text": "Two, Three"},
{"text": "Three, One"},{"text": "Three, Two"},{"text": "Three, Three"}];
“文本”字段描述了每个元素应出现在 3x3 网格矩阵中的哪个位置。我想在 objects 上使用 ng-repeat 来生成如下所示的 html:
<table>
<tr>
<td>One, One</td>
<td>One, Two</td>
<td>One, Three</td>
</tr>
<tr>
<td>Two, One</td>
<td>Two, Two</td>
<td>Two, Three</td>
</tr>
<tr>
<td>Three, One</td>
<td>Three, Two</td>
<td>Three, Three</td>
</tr>
</table>
有没有什么方法可以实现这一点,而无需将数组分解为每一行的单独数组?
【问题讨论】:
-
这篇文章或许对你有帮助:stackoverflow.com/questions/15973985/…
-
你好 Cumulo,你是想列出三三两两还是其他的东西?
-
感谢@arman1991 的参考,但该示例使用多个数组,每行一个;我只想对多行使用一个数组。 katmanco 实际文本无关紧要,我只是想传达每个“文本”字符串对象应该去哪里的想法
-
@PSL 是的!如果您可以发布该答案并在您所做的事情背后稍作解释,我将很乐意接受。谢谢!
标签: arrays angularjs html-table ng-repeat