在我的render方法中,我正在调用一个基于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'
答案 0 :(得分:1)
错误是因为在某些情况下,您正在从助手方法返回numeral
对象而不是文本字符串。这让React感到困惑。
你可能想要
return numeral(qty).format('0,000');
而不是
return numeral(qty)