2016-01-14 31 views
2

我試圖調用一個雙重嵌套的ng-repeat來遍歷對象中的對象,並且它不起作用。我使用的表(TR,TD)嵌套的ng-repeat無法正常工作

這是我的HTML代碼:

<tr ng-repeat="row in rows"> 
    <td ng-repeat="item in row"> 
    {{item}} 
    </td> 
</tr> 

這是我的數據對象:

$scope.rows = [["10:00", "0"],["12:00","1"]] 

但表不顯示任何信息。我做錯了什麼?謝謝!

UPDATE

的計算器例子做工精細,對不起。

用我原來的數據數組不起作用:

[["10:00","0","0","3","0","0","0","0"],  
["12:00","0","0","3","0","0","0","0"], 
["14:00","0","0","3","0","0","0","0"], 
["16:00","0","0","3","0","0","0","0"], 
["18:00","0","0","3","0","0","0","0"], 
["20:00","0","0","3","0","0","0","0"], 
["22:00","0","0","3","0","0","0","0"]] 

我想創造的東西,如:

enter image description here

+0

並沒有被打印在所有(沒有TR或TD標籤)表或只是在{{項目}}沒有被填充模式是什麼? – Seonixx

+0

它適用於我,如果你刪除'ítem'中的尖銳i(í)並使用'item'代替 – user2718281

+0

ng-repeat不會創建td – pekpon

回答

1

當您的樣本數據運行你的代碼完全如圖所示,在控制檯日誌中記錄以下錯誤:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in row, Duplicate key: string:0, Duplicate value: 0

這可以通過將track by表達式添加到您的ng-repeat來解決。由於您沒有將數據中的特定列用作索引,因此可以使用ng-repeat$index特殊屬性。

<tr ng-repeat="row in rows"> 
    <td ng-repeat="item in row track by $index"> 
    {{item}} 
    </td> 
</tr> 

此代碼會給你預期的輸出。

http://plnkr.co/edit/aSbaom85JsQwUfTIwKk3?p=preview

相關問題