Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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
Arrays 在阵列中循环并将其拼接到reactJS中_Arrays_Reactjs_For Loop_Splice - Fatal编程技术网

Arrays 在阵列中循环并将其拼接到reactJS中

Arrays 在阵列中循环并将其拼接到reactJS中,arrays,reactjs,for-loop,splice,Arrays,Reactjs,For Loop,Splice,我想检查一个用户提及的帖子,并插入一个链接到用户档案的用户名。第一次提到它时,它是这样工作的: if (mentions.length > 0) { const splitSearch = '@' + mentions[0].user.name; children = text.split(splitSearch); for (let i = children.length - 1; i > 0; i--) { const a = (

我想检查一个用户提及的帖子,并插入一个链接到用户档案的用户名。第一次提到它时,它是这样工作的:

  if (mentions.length > 0) {
    const splitSearch = '@' + mentions[0].user.name;
    children = text.split(splitSearch);

    for (let i = children.length - 1; i > 0; i--) {
      const a = (
        <a href={`profile/${mentions[0].user._id}`}>@{mentions[0].user.name}</a>
      );
      children.splice(i, 0, a);
    }
  }
if(references.length>0){
const splitSearch='@'+提到[0]。user.name;
children=text.split(splitSearch);
for(设i=childrence.length-1;i>0;i--){
常数a=(
);
拼接(i,0,a);
}
}
我尝试了一个for循环:

  if (mentions.length > 0) {
    for (let index = 0; index < mentions.length; index++) {
      const splitSearch = '@' + mentions[index].user.name;
      children = text.split(splitSearch);

      for (let i = children.length - 1; i > 0; i--) {
        const a = (
          <a href={`profile/${mentions[index].user._id}`}>
            @{mentions[index].user.name}
          </a>
        );
        children.splice(i, 0, a);
      }
    }
  }
if(references.length>0){
for(让index=0;index0;i--){
常数a=(
);
拼接(i,0,a);
}
}
}
我想问题是结果没有保存,只是被下一个循环螺母覆盖了。我不知道如何解决这个问题

提前谢谢