理解React.js中数组子元素的唯一键
数组中的每个子数组都应该有一个唯一的“键”支柱。 检查TableComponent的呈现方法。
TableComponent
<table>
<thead key="thead">
<TableHeader columns={columnNames}/>
</thead>
<tbody key="tbody">
{ rows }
</tbody></table>TableHeader
rowrows
<TableRowItem key={item.id} data={item} columns={columnNames}/>TableRowItem
var TableRowItem = React.createClass({
render: function() {
var td = function() {
return this.props.columns.map(function(c) {
return <td key={this.props.data[c]}>{this.props.data[c]}</td>;
}, this);
}.bind(this);
return (
<tr>{ td(this.props.item) }</tr>
)
}});
一只名叫tom的猫
随时随地看视频慕课网APP