ils*_*005 4 datepicker reactjs
我开始使用react-datepicker组件. https://github.com/Hacker0x01/react-datepicker
我让示例运行,现在我想调整它没有初始值.示例代码如下:
<script type="text/javascript">
var container = document.querySelector('#datepicker-container');
var exampleComponent = React.createClass({
displayName: 'exampleComponent',
getInitialState: function() {
return {
start_date: moment(),
};
},
handleStartDateChange: function(date) {
this.setState({
start_date: date
});
},
render: function() {
return React.DOM.div({}, [
DatePicker({
key: 'example1',
selected: this.state.start_date,
onChange: this.handleStartDateChange
}),
]);
}
})
React.renderComponent(exampleComponent(), container);
</script>
Run Code Online (Sandbox Code Playgroud)
我试图使用selected: none甚至遗漏selected,但后来我收到以下错误:
TypeError: newProps.date is null
value: newProps.date.format(this.props.dateFormat)
Run Code Online (Sandbox Code Playgroud)
我也查看了源代码,但没有发现任何以空日期开头的可能性.在此先感谢您的帮助!
你应该能够通过设置start_date: null,实现你想要的getInitialState,
或者,如果您使用react-datepicker中的示例3,则可以定义如下函数:
handleResetDate: function() {
this.setState({
new_date: null
});
},
Run Code Online (Sandbox Code Playgroud)
,并在需要重置日期时调用它.
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
6970 次 |
| 最近记录: |