在我的渲染方法中,我调用了一个方法,它根据 API 响应数据执行一些条件逻辑。考虑到我没有从 DOM 中删除任何内容,我不清楚如何解决此错误。这是我的方法
import numeral from 'numeral';
import moment from 'moment';
class SearchResultsListItem extends React.Component {
constructor(props) {
this.isMaxQtyGreaterThanOneThousand=
::this.isMaxQtyGreaterThanOneThousand;
}
isMaxQtyGreaterThanOneThousand(qty){
if(!!qty){
if(qty%1000 === 0){
return (numeral(qty).divide(1000).format('0,000') + 'M');
}else{
return numeral(qty);
}
}else{ return "-";}
}
render() {
const x = this.props.dataItem;
return (
<div className={`${s['quantity-block']}`}>
{this.isMaxQtyGreaterThanOneThousand(x.MaxQuantity)}
</div>
)
}
为了解决这个错误,我查看了以下帖子,但没有找到任何特定于 jsx 或 React 的东西:
Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'
最佳答案
该错误是因为在某些情况下,您返回的是 numeral
对象而不是辅助方法中的文本字符串。这让 React 很困惑。
你可能想要
return numeral(qty).format('0,000');
代替
return numeral(qty)
关于javascript - 类型错误 : Failed to execute 'removeChild' on 'Node' : parameter 1 is not of type 'Node' in React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45741052/