AngularJs的伟大系列

AngularJs ngRepeat series?

本文关键字:大系列 伟大 AngularJs      更新时间:2023-09-26

我有一系列这样的对象:

[[null,"SUPPER",7],[1436306400000,"SUPPER",2],[1436220000000,"SUPPER",1],[null,"DINNER",2],[1436133600000,"BREAKFAST",1],[1436133600000,"SUPPER",2],[null,"BREAKFAST",1],[1436392800000,"DINNER",1]]

我如何写每个对象在表行与ngRepaat?

这是一个工作的活塞http://plnkr.co/edit/Fgsrx8VzRfPG7y9seTwQ?p=preview

<table border=1>
    <tr ng-repeat="tr in data">
        <td ng-repeat="td in tr">{{ td || '&nbsp;'}}</td>
    </tr>
</table>

将此表分配给作用域,然后在模板中使用类似的内容:

<!-- Assumes the table you posted is available as "els" on the scope -->
<table>
    <tr ng-repeat="e in els">
        <!-- In each table cell, use the first, second and third
             element from the array you have.
             Note: since some of the values are null, I added the
             '|| "empty"] to fallback with some message. -->
        <td>{{ e[0] || "empty" }}</td>
        <td>{{ e[1] || "empty" }}</td>
        <td>{{ e[2] || "empty" }}</td>
    </tr>
</table>

DEMO:这个JSFiddle有一个工作演示,以及控制器。