简体   繁体   English

如何解决'每个孩子都应该有一个独特的关键道具?

[英]How to Fix 'Each child should have a unique key prop?

Hi everyone I would like to display for each element all of its sub-documents.大家好,我想为每个元素显示其所有子文档。

  <div><ul>{designModdulles.map((designModdulle)=><li key={designModdulle.epreuves.nature_epreuve}>{designModdulle.epreuves.nature_epreuve}</li>) }</ul></div>
```
I wanted the sub documents to be displayed` in a map
but i had: Warning: Each child in a list should have a unique "key" prop.

Assuming this is JavaScript, the cause of the issue is that there are duplicate key values.假设这是 JavaScript,问题的原因是存在重复的key You can use the index of each map entry to create a new key您可以使用每个映射条目的索引来创建一个新键

<div><ul>{designModdulles.map((designModdulle, index)=><li key={designModdulle.epreuves.nature_epreuve + index}>{designModdulle.epreuves.nature_epreuve}</li>) }</ul></div>

You may want to look at the following to see what your choices are (there are other resources as well): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map您可能想查看以下内容以了解您的选择(还有其他资源): https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

the problem of the key is resolved, but nothing is displayed in the key的问题解决了,但是里面没有任何显示

  • tag标签

  • hello everyone here is the solution:大家好这里是解决方案:

    <ul><li>{designModdulles.map((item,index)=>(<div key={index}>{item.epreuves.map((c, i)=>(<div key={i}>
           <h3>{c.code_epreuve}</h3><Button>Insérer notes</Button><Button>Supprimer</Button> </div>) )}</div>))}</li></ul>
    

    thank you谢谢你

    暂无
    暂无

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

    相关问题 列表中的每个孩子都应该有一个独特的“关键”道具。 我有钥匙,但错误仍然存在 - Each child in a list should have a unique "key" prop. I have the key but the error remains 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 检查`Notes`的渲染方法 - Warning: Each child in a list should have a unique "key" prop. Check the render method of `Notes` 这是从哪里来的:警告:列表中的每个孩子都应该有一个唯一的“关键”道具 - Where is this coming from: Warning: Each child in a list should have a unique “key” prop Condense List[Dict[key, list]] 以便重复键的列表转换为每个唯一键的列表列表 - Condense List[Dict[key, list]] so that duplicated keys have their lists converted to list of lists for each unique key 唯一的“关键”道具不适用于我的数组映射 - 反应 - Unique "key" prop not working for my array mapping - REACT 使用唯一的“key”道具反应过滤器项目和 null 比较 - React filter item with the unique “key” prop and is null comparison 如何计算包含列表的字典中每个键的每个唯一值? - How do I count each unique value for each key in a dictionary containing lists? 具有每个键唯一可能值的字典? - A dictionary with a unique possible value for each key? 如何使用 dict.fromkeys 为每个键创建唯一值? - How do I create a unique value for each key using dict.fromkeys? Python:如何遍历词典列表并将每个词典作为值添加到具有唯一键的新词典中-无需重复 - Python: How to iterate over a list of dictionaries and add each dictionary as value to a new dictionary with a unique key - no repeats
     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM