gpt4 book ai didi

javascript - React JS - 未捕获的 NotFoundError : Failed to execute 'insertBefore' on 'Node' :

转载 作者:行者123 更新时间:2023-12-01 16:00:14 31 4
gpt4 key购买 nike

我有一个 div里面另外三个div s 附加如下。状态值是通过循环来自 componentWillReceiveProps() 的 api 的结果来设置的。 .但我面临一个错误问题

Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node



如果 api 结果为 null 获取

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.



我怎样才能解决这个问题?
componentWillReceiveProps(nextProps) {
var sub1 = [], sub2 = [], sub3 = [];
if(result) {
result.sub1.map((item, index) => {
sub1.push(
<div>
<p>{item.name}</p>
</div>
)
})
result.sub2.map((item, index) => {
sub2.push(
<div>
<p>{item.name}</p>
</div>
)
})
result.sub3.map((item, index) => {
sub3.push(
<div>
<p>{item.name}</p>
</div>
)
})

this.setState({ subDiv1:sub1, subDiv2:sub2, subDiv3:sub3 })
}
}

render() {
return(
<div className="row top_bar">
<div className="search left col-xs-5 col-sm-4 col-md-5 col-lg-6">
<form>
<input type="text" id="search_box" name="search_box" placeholder="Search" onKeyUp={this.keyUpFn} />
</form>
<div className="div1">
{ this.state.subDiv1 }
{ this.state.subDiv2 }
{ this.state.subDiv3 }
</div>
</div>
<div className="top_right col-xs-7 col-sm-8 col-md-7 col-lg-6">
<div className="top_outer">
</div>
</div>
</div>
)
}

最佳答案

有时当用户使用谷歌翻译时会发生这种情况,它会改变文本节点,并且 React 在下一次渲染时会中断。
更多信息以及如何解决它:
https://github.com/facebook/react/issues/11538#issuecomment-390386520
您还可以将下一个属性添加到 HTML 标记以禁用 Google 翻译并解决此问题:<html class="notranslate" translate="no">

关于javascript - React JS - 未捕获的 NotFoundError : Failed to execute 'insertBefore' on 'Node' :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50784302/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com