DatePicker禁用错误
问题描述:
我想创建一个组件,它由使用ReactJs和office365的Datepicker和ChoiceGroup组成。在第一次渲染日期选择器必须禁用,当我们在ChoiceGroup的选择定制单选按钮,它必须是代码enabled.Piece:DatePicker禁用错误
<div>
<ChoiceGroup
defaultSelectedKey='all'
onChange={ this._onChange }
label='Date'
options={ [
{
key: 'all',
text: 'All'
},
{
key: 'thisWeek',
text: 'This week',
},
{
key: 'lastWeek',
text: 'Last week',
},
{
key: 'thisMonth',
text: 'This month',
},
{
key: 'custom',
text: 'Custom',
}
] }
/>
<DatePicker
label='label'
isRequired={ false }
disabled={ pickerDisabled }
strings={ strings }
allowTextInput={ false }
value={ value }
/>
</div>
选择器具有disabled
PARAM,我想改变它在ChoiceGrou方法:
onChange = (ev, option) => {
console.dir(option);
if(option.key === 'custom') {
this.setState({
pickerDisabled: false
})
} else {
this.setState({
pickerDisabled: true
})
}
}
此方法工作并更改参数,但datepicker组件的禁用不会更改。它仍然是相同的,当我点击任何单选按钮,我得到了在控制台错误:
Exception in DatePicker.componentWillReceiveProps(): TypeError: date1.getFullYear is not a function
什么可以这个错误的原因是什么?
答
看来要传递一个无效的value
到DatePicker
成分,我的猜测(没有更多的上下文/ INFO)是value
是null
/undefined
默认和DatePicker
默认为当前日期,但value
被设定通过单选按钮,它不是一个有效的值(基于错误,它看起来像DatePicker
期待Date
对象(它试图调用getFullYear()
),但value
是一个字符串)。
检查DatePicker
组件的文档以了解其在value
prop中的相应内容。
你是对的我把新的日期()值和它的工作原理,谢谢 –