0
在json feed中(下面)我有兩個數組,「rent」和「buy」我希望加入並顯示在html表中,但我不知道該在哪裏做。在反應中加入數組render render功能
飼料看起來像這樣...
"store": {
"rent": [
{ "title": "Lord of the ring masters", "cost": 2.99 }
],
"buy": [
{ "title": "Fast and Furious 14", "cost": 5.99 },
{ "title": "Shogun Assassin", "cost": 2.99 }
],
"total": 30.20
}
而且在我看來,渲染功能,這將顯示上述的一個正確看起來像這樣
render: function(){
var createRow = function(rowItem, i){
return (
<tr key={i}>
<td>{rowItem.name}</td>
<td>{rowItem.cost}</td>
</tr>
);
};
return (
<div>
<h1>Package</h1>
<table className="table">
<thead>
<th>Package</th>
<th>Name</th>
<th>Cost</th>
</thead>
<tbody>
{this.props.packageList.rent.map(createRow, this)}
</tbody>
</table>
Total: {this.props.packageList.total}
</div>
);
}
可以在任何一個告訴我我如何改變上述加入陣列並呈現像這樣的數據...
**Rent** Lord of the ring masters £2.99
**Buy** Fast and Furious 14 £5.99
**Buy** Shogun Assassin £2.99
謝謝。它工作,但我不得不從每行刪除鍵,因爲它不會顯示所有的行。也許因爲重複? –
從DOM:遇到兩個具有相同密鑰的孩子,'。$ 1'。子鑰匙必須是唯一的;當兩個孩子分享一把鑰匙時,只有第一個孩子會被使用 –
好的 - 只需加上{key =「rent」+ i} –