[英]Each child in an array or iterator should have a unique "key" prop
was getting the warning message (正在收到警告消息(
) in the below code using react.js.
) 在下面的代码中使用 react.js。 I checked answers on the stackoverflow and tried to remove the warning message but it didn't help.
我检查了 stackoverflow 上的答案并尝试删除警告消息,但没有帮助。 Made a separate example with similar functionality in a static page and it is working fine.
在静态页面中制作了一个具有类似功能的单独示例,并且工作正常。 But, this code is throwing warning message.
但是,此代码正在抛出警告消息。 How to remove this warning message ?
如何删除此警告消息?
<tbody>
{list.map(function(value){
return(<tr className="gradeA" role="row">
<td className="sorting_1">{ value.id }</td>
<td>{value.name}</td>
<td>{value.location}</td>
</tr>);
})
}
</tbody>
You just need to add a unique key to the returned component from map.您只需要为 map 返回的组件添加一个唯一键。 In your map function receive define another parameter as key and for each
tr
that you return just add key={key}
as a prop.在您的 map 函数中,将另一个参数定义为 key,对于您返回的每个
tr
,只需添加key={key}
作为 prop。
<tbody>
{list.map(function(value, key){
return(<tr className="gradeA" role="row" key={key}>
<td className="sorting_1">{ value.id }</td>
<td>{value.name}</td>
<td>{value.location}</td>
</tr>);
})
}
</tbody>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.