嗨,我想创建一个表(学校课程表)基于一个虚拟数据,这是在json对象格式。该对象如下所示。
this._days=[
{
"day": "",
"config": {}
},
{
"day": "Monday",
"config": {
'timing': [
{'time': '9:00AM-10:00AM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
},
{'time': '10:00AM-11:00AM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
},
{'time': '11:00AM-11:30AM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
},
{'time': '12:00PM-12:30PM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
}
]
}
},
{
"day": "Tuesday",
"config": {
'timing': [
{'time': '9:00AM-10:00AM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
},
{'time': '10:00AM-11:00AM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
},
{'time': '11:00AM-11:30AM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
},
{'time': '12:00PM-12:30PM',
'schedule': {'subject': 'Physics','teacher': 'Amanda','Location': 'Room 05'}
}
]
}
},
...基于dummydata,我想创建一个表,这样即使对象的大小增加了(例如:星期六的课或额外的时间),表也应该自动调整。该表应该看起来像一个正常的学校时间表,在左边有日期、标题和时间。我用硬编码的值创建了一个基本表,
<table width="100%" align="center" height=100%;>
<tr class="day">
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thrusday</th>
<th>Friday</th>
<th>Saturday</th>
</tr>
<tr class="time">
<th>10:00 - 11:00</th>
<td>Physics-1</td>
<td>English</td>
<td></td>
<td>Chemestry-1</td>
<td>Alzebra</td>
<td>Physical</td>
</tr>
<tr class="time">
<th>11:00 - 12:00</th>
<td>Math-2</td>
<td>Chemestry-2</td>
<td>Physics-1</td>
<td>Hindi</td>
<td>English</td>
<td>Soft Skill</td>
</tr>
<tr class="time">
<th>12:00 - 01:00</th>
<td>Hindi</td>
<td>English</td>
<td>Math-1</td>
<td>Chemistry</td>
<td>Physics</td>
<td>Chem.Lab</td>
</tr>
<tr class="time">
<th>01:00 - 02:00</th>
<td>Cumm. Skill</td>
<td>Sports</td>
<td>English</td>
<td>Computer Lab</td>
<td>Header</td>
<td>Header</td>
</tr>
<tr class="time">
<th>02:00 - 03:00</th>
<td>Header</td>
<td>Header</td>
<td>Header</td>
<td>Header</td>
<td>Header</td>
<td>Header</td>
</tr>
</table>我试过这样的东西
<div>
<table style="width:100%; height:200px;">
<tr>
<th *ngFor="let row of _days" style="background: grey; color:white">
<h3><b>{{row.day}}</b></h3>
</th>
</tr>
<tr *ngFor="let row of _days">
<td style="background: grey;color:white">
<h3><b>{{row.config.timing[row].time}}</b></h3>
</td>
</tr>
</table>
</div>如何在javascript或Angular 2 (typescript)中实现这一点?提前谢谢伙计们
发布于 2017-04-05 13:56:31
您可以在angular 2中使用primeng datatable。
在您模块中使用
import {DataTableModule,SharedModule} from 'primeng/primeng';超文本标记语言中的给出
<p-dataTable [value]="cars">
<p-column field="vin" header="Vin"></p-column>
<p-column field="year" header="Year"></p-column>
<p-column field="brand" header="Brand"></p-column>
<p-column field="color" header="Color"></p-column>
</p-dataTable>component中的
public cars: Car[];
constructor(private http: Http) { }
ngOnInit() {
this.http.get('data.json')
.map(res => res.json())
.subscribe(data => this.cars = data,
err => console.log(err),
() => console.log('Completed'));
}
}您可以在Angular2 https://www.primefaces.org/primeng/#/datatable中使用PrimeNG数据表
https://stackoverflow.com/questions/43220338
复制相似问题