【发布时间】:2017-03-02 05:23:02
【问题描述】:
我正在尝试迭代这个 JSON,以便我可以制作一个表格,但是由于有很多标题和很多数据,我怎么能不这样做。
const BBDDCustomer = {
ui_labels: {
name: 'Name',
address: 'address',
postalCode: 'Postal Code',
city: 'City',
country: 'Country',
telephone: 'Telephone',
email: 'Email',
modified: 'Modified',
delete: 'Delete'
},
data: [
{
name: 'n1',
address: 'a1',
postalCode: 'PC 1',
city: 'c 1',
country: 'cou 1',
telephone: 'tel 1',
email: 'em 1'
}
}
我不必这样写:
<table striped bordered condensed hover responsive>
<thead>
<tr>
<th>{BBDDCustomer.ui_labels.name}</th>
<th>{BBDDCustomer.ui_labels.address}</th>
<th>{BBDDCustomer.ui_labels.postalCode}</th>
<th>{BBDDCustomer.ui_labels.city}</th>
<th>{BBDDCustomer.ui_labels.country}</th>
<th>{BBDDCustomer.ui_labels.telephone}</th>
<th>{BBDDCustomer.ui_labels.email}</th>
<th>{BBDDCustomer.ui_labels.modified}</th>
<th>{BBDDCustomer.ui_labels.delete}</th>
</tr>
</table>
【问题讨论】:
-
这不是 JSON > what?
-
您可以将
Object.keys与map结合使用。但不保证属性的顺序。 -
答案就在问题中,不是吗?映射您的结构并渲染。你需要学会做出反应来做到这一点
标签: javascript json reactjs