Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ESLint错误:列表中的每个子项都应该有一个唯一的;“关键”;道具_Javascript_Json_Reactjs_Eslint - Fatal编程技术网

Javascript ESLint错误:列表中的每个子项都应该有一个唯一的;“关键”;道具

Javascript ESLint错误:列表中的每个子项都应该有一个唯一的;“关键”;道具,javascript,json,reactjs,eslint,Javascript,Json,Reactjs,Eslint,我有一个JSON字符串,如下所示。该字符串已为下一行指定\n data:{a:"A computer is a machine that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming. Modern computers have the ability to follow generalized sets of

我有一个JSON字符串,如下所示。该字符串已为下一行指定\n

data:{a:"A computer is a machine that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming. Modern computers have the ability to follow generalized sets of operations, called programs. These programs enable computers to perform an extremely wide range of tasks. A "complete" computer including the hardware, the operating system (main software), and peripheral equipment required and used for "full" operation can be referred to as a computer system. This term may as well be used for a group of computers that are connected and work together, in particular, a computer network or computer cluster.\nComputers are used as control systems for a wide variety of industrial and consumer devices. This includes simple special purpose devices like microwave ovens and remote controls, factory devices such as industrial robots and computer-aided design, and also general-purpose devices like personal computers and mobile devices such as smartphones. The Internet is run on computers and it connects hundreds of millions of other computers and their users."}
我在React中使用了它,如下所示:

const b = data.a.split("\n");
return(
<P>
b.map((p,index)=>({p}<br key={index}/>))
</p>
我怎样才能避免警告呢?我需要段落标记中的文本,文本中的每一行都用

{p}

)替换
b.map((p,index)=>(<p key={index}>{p}</p>))
您需要包装元素上的键。只要使用
p
标签,您就可以免费获得换行符


但是,使用索引作为键是有原因的。

您需要将
属性设置为从
映射
返回的项,而不是

元素

试着这样做:

<P>
  { React.Children.toArray(b.map((p,index)=>({p}<br/>))) }
</p>

{React.Children.toArray(b.map((p,index)=>({p}
))}


这是否回答了您的问题@看起来很像,但这里我有一个不同的问题。如果我喜欢我标记的正确方法,那么我需要删除CSS中的填充和边距。因此我使用上述方法。是的,我有一个填充问题,因此,我尝试使用有问题的方法。现在,我删除填充并使用此方法。谢谢你的帮助。
<P>
  { React.Children.toArray(b.map((p,index)=>({p}<br/>))) }
</p>