我有這樣使用自定義功能反應
class Hourly extends Component {
render() {
return (
<div key={this.props.key} id={this.props.id} className="col-xs-3 text-center vcenter box parent">
<div className="child">
<div>{this._theDay(this.props.day)}</div>
<div>{this.props.summary}</div>
</div>
</div>
);
}
}
我想我在另一個組件後使用組件使用自定義函數(_theDay)組件
自定義功能:
_theDay(time) {
moment.locale('en-gb');
var dateTime = moment(time*1000).format('dddd');
return dateTime;
}
我調用組件後來與
<Hourly
key={hour.time}
id={hour.time}
day={hour.time}
summary={hour.summary}
/>
但是我得到的錯誤:Uncaught (in promise) DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.(…)
當我只是用<div>{this.props.day}</div>;
一切工作正常,但後來我不能使用我的自定義功能
試圖重現您的問題,似乎爲我工作: -/http://jsbin.com/wuqupehaqa/edit?html,js,output – BFree
嗯我可以看到, ...我嘗試重新組織我的代碼,就像在你的例子中,現在告訴我'_this4._theDay不是一個函數' – frisk0
對,所以我把'_theDay'函數放在Hourly類中,我猜測'因爲你需要在其他地方重新使用該功能,所以不適合你。如果是這樣的話,調用它時不要使用'this._Day',並將函數放置在兩個組件都可以訪問的地方。 – BFree