我想使用anguler js创建以下动态列表。
根据我的要求,水果,蔬菜等列集可以根据数据集动态变化。我想从json文件加载数据。 例如:
[
{
"clusterID":"1",
"storeCode": "S2HK",
"storeName": "store 1",
"Vegetables":
{
"Ordered":"272",
"Delivery":"250",
"FR":"70%",
"Gap":"22"
},
"Fruit":
{
"Ordered":"300",
"Delivery":"250",
"FR":"60%",
"Gap":"50"
}
},
{
"clusterID":"1",
"storeCode": "SCCC",
"storeName": "store 2",
"Vegetables":
{
"Ordered":"500",
"Delivery":"500",
"FR":"100%",
"Gap":"0"
},
"Fruit":
{
"Ordered":"750",
"Delivery":"700",
"FR":"90%",
"Gap":"50"
}
}
]
我尝试了很多方法,但是无法创建动态表。如何创建这种类型的表?
答案 0 :(得分:0)
您需要使表结构如下:
<table border="1" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th rowspan="2">Store</th>
<th rowspan="2">Store Name</th>
<th colspan="4">Vegetables</th>
<th colspan="4">Fruit</th>
</tr>
<tr>
<th>Ordered</th>
<th>Delivery</th>
<th>FR</th>
<th>Gap</th>
<th>Ordered</th>
<th>Delivery</th>
<th>FR</th>
<th>Gap</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of items">
<td>item.storeCode</td>
<td>item.storeName</td>
<td>item.Vegetables.Ordered</td>
<td>item.Vegetables.Delivery</td>
<td>item.Vegetables.FR</td>
<td>item.Vegetables.Gap</td>
<td>item.Fruit.Ordered</td>
<td>item.Fruit.Delivery</td>
<td>item.Fruit.FR</td>
<td>item.Fruit.Gap</td>
</tr>
</tbody>
您可以看到正在运行的jsBin here