<分区>
我有将其值发送给函数的表单:
_onChange(ev, option) {
console.log(option.key) // option.key = 3
this.setState({ dropdownValue:option.key }) // option key = "undefined"
}
正如您在上面看到的,我可以打印出该值,例如 3。但是,当我随后尝试将其直接添加到状态时,出现错误“无法设置未定义的状态”。
我已尝试将值添加到变量,然后将其用于 setState,但我仍然遇到该错误。怎么会?
我的 onChange 方法:
<ChoiceGroup
className="defaultChoiceGroup"
defaultSelectedKey="B"
options={[
{
key: '1',
text: 'test'
},
{
key: '2',
text: 'test2'
},
{
key: '3',
text: 'test3',
}
]}
onChange={this._onChange }
label="Change password for..."
required={true}
/>