2016-12-31 53 views
1

想要創建一個像這樣的表 enter image description here帶有ng-repeat的全月視圖表?

(忽略樣式)。我弄糊塗瞭如何合成數據以在html中製作此表。

$scope.toddlers = [ 
{ 
    "name": "a", 
    "day": 1, 
    "total": 3 
}, 
{ 
    "name": "b", 
    "day": 2, 
    "total": 4 
}, 
{ 
    "name": "c", 
    "day": 4, 
    "total": 1 
} 
]; 

我想我需要改變我的數據格式或者我不能讓這張表正確。我應該如何格式化我的數據才能得到這個結果。

僅供參考:我通過使用mongodb聚合獲取我的數據。

plunker link

+1

這是*不可能*回答問題,因爲它是目前提出。您發佈了可能佈局的屏幕截圖,但沒有任何代碼顯示任何HTML,以及與提供的屏幕截圖無關的數組的單個代碼段。 – Claies

+0

添加了一個plunker鏈接,請再次檢查 –

回答

1

這個片段可以產生你希望的佈局:

<table border="1"> 
    <tr> 
    <th></th> 
    <th ng-repeat="day in days">{{day}}</th> 
    </tr> 
    <tr ng-repeat="toddler in toddlers"> 
    <td>{{toddler.name}}</td> 
    <td ng-repeat="day in days"> 
     <span ng-if="toddler.day === day">{{toddler.total}}</span> 
     <span ng-if="toddler.day !== day">0</span> 
    </td> 
    </tr> 
</table> 

它首先重複天th,有一個額外的th所有的天之前。那麼如果當前學步日與當天匹配,則顯示toddler.total,否則0使用ng-if指令。