簡體   English   中英

AngularJS在表格中使用ng-repeat兩次

[英]AngularJS using ng-repeat twice in a table

這個問題來自AngularJS.org教程我們用這段代碼創建了一個表:

<table>
  <tr><th>row number</th></tr>
  <tr ng-repeat="i in [0, 1, 2, 3, 4, 5, 6, 7]"><td>{{i+1}}</td></tr>
</table>

這給了我們一排表。 額外的挑戰是使用額外的ng-repeat制作8x8表。 我已經嘗試了幾次以不同的方式通過添加ng-repeat創建7個額外的列,但我幾乎總是以第9行代碼而不是數據結束。

順便說一句,實際上沒有積分; 我只想要知識。

這將使用嵌套的ng-repeat創建一個8x8表:

<table>
  <tr ng-repeat="i in [0, 1, 2, 3, 4, 5, 6, 7]">
    <td ng-repeat="j in [0, 1, 2, 3, 4, 5, 6, 7]">{{j}}</td>
  </tr>
</table>

如果這個問題仍然存在 - 這里有兩個填充表的變體 - 逐行和逐列(從1到8)。 <tr><td>使用嵌套指令ng-repeat

行到行:

<table>
    <tr><th colspan="8">Row number</th></tr>
    <tr ng-repeat = "i in [0, 1, 2, 3, 4, 5, 6, 7]">
        <td ng-repeat = "j in [0, 1, 2, 3, 4, 5, 6, 7]">{{j+1}}</td>
    </tr>
</table>

列逐列:

<table>
  <tr><th colspan="8">Row number</th></tr>
    <tr ng-repeat = "i in [0, 1, 2, 3, 4, 5, 6, 7]">
        <td ng-repeat = "j in [0, 1, 2, 3, 4, 5, 6, 7]">{{i+1}}</td>
    </tr>   
</table>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM