理解React.js中數(shù)組子元素的唯一鍵我正在構(gòu)建一個(gè)Reaction組件,它接受JSON數(shù)據(jù)源并創(chuàng)建一個(gè)可排序的表。每個(gè)動(dòng)態(tài)數(shù)據(jù)行都有一個(gè)分配給它的唯一鍵,但我仍然得到以下錯(cuò)誤:數(shù)組中的每個(gè)子數(shù)組都應(yīng)該有一個(gè)唯一的“鍵”支柱。檢查TableComponent的呈現(xiàn)方法。我的TableComponentRender方法返回:<table>
<thead key="thead">
<TableHeader columns={columnNames}/>
</thead>
<tbody key="tbody">
{ rows }
</tbody></table>這個(gè)TableHeader組件是一個(gè)單行,并且有一個(gè)分配給它的唯一鍵。各row在……里面rows是由具有唯一鍵的組件生成的:<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>
)
}});是什么導(dǎo)致了唯一的鍵支柱錯(cuò)誤?
理解React.js中數(shù)組子元素的唯一鍵
一只名叫tom的貓
2019-06-12 21:15:46