简体   繁体   English

数组或迭代器中的每个孩子都应该有一个唯一的“key” prop

[英]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.

相关问题 数组或迭代器中的每个子代在reactjs中都应具有唯一的“键”道具 - Each child in an array or iterator should have a unique “key” prop in reactjs 警告:数组或迭代器中的每个子代都应具有唯一的“键”道具 - Warning :Each child in an array or iterator should have a unique “key” prop React - 数组或迭代器中的每个子节点都应该有一个唯一的“key”prop - React - Each child in an array or iterator should have a unique “key” prop 警告:数组或迭代器中的每个孩子都应该有一个唯一的“键”道具 - Warning: Each Child in an Array or Iterator Should Have a Unique “Key” Prop 警告:数组或迭代器中的每个子代都应具有唯一的“键”道具。 li中已添加的关键道具 - Warning: Each child in an array or iterator should have a unique “key” prop.; key prop already added in li 数组或迭代器中的每个子代都应具有唯一的键道具-但我确实定义了一个键道具 - each child in an array or iterator should have a unique key prop - but i did define a key prop 持久警告:“即使已经设置了密钥,数组或迭代器中的每个子节点都应该具有唯一的&#39;密钥&#39;prop” - Persistent Warning: “Each child in an array or iterator should have a unique 'key' prop” even if key is already set 警告:数组或迭代器中的每个子代均应具有唯一的“键”道具。 检查`单位`的渲染方法 - Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of `Units` 跟踪数组或迭代器中的每个子代均应具有唯一的“键”道具 - tracking down Each child in an array or iterator should have a unique “key” prop 警告:数组或迭代器中的每个子代均应具有唯一的“键”道具。 检查“搜索”的渲染方法 - Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of 'search'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM