0
我想將日期選擇器集成到一個反應組件。我正在使用pickaday jQuery庫的日期選擇器。爲了實現這個,我創建了以下組件。添加一個jQuery的日期選擇器來反應組件
DatePicker.js.jsx
var DatePicker = React.createClass({
//This is a callback to parent component for updating the state
changeDuration: function (date) {
this.props.changeDuration(this.props.id, date);
},
componentDidMount: function() {
_self = this;
new Pikaday({
field: document.getElementById(this.props.id),
format: 'D MMM YYYY',
onSelect: function() {
_self.changeDuration(this.getMoment())
},
minDate: this.props.minDate
});
},
render: function() {
return (
<input type="text" name={this.props.name} id={this.props.id} defaultValue={this.props.value}/>
)
}
});
這裏的問題是,在第一頁加載我可以選擇的日期選擇器和它的作品如預期,但如果我再次改變它無需重新加載它不會工作,在控制檯中顯示以下錯誤。
Uncaught TypeError: _self.changeDuration is not a function
有人能告訴我什麼在做錯嗎?
_self =此;應該是var _self = this; – Ved
@ved完全...坎特相信這是問題所在。從昨天開始我一直在擺弄這件事。感謝很多 – Abhilash