我正在使用redux格式v8.1.0。 db中有一个布尔字段IsCompulsary。 如何使“是”检查为真,如何使“否”检查为假?
<div>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
/>{' '}
Yes
</label>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
/>{' '}
No
</label>
</div>
更新:
在组件底部:
SchoolSettings = reduxForm({
form: "schoolSettingsForm", // a unique identifier for this form
enableReinitialize: true
})(SchoolSettings);
SchoolSettings = connect(
state => ({
initialValues: state.schoolSettings.data // pull initial values from account reducer
})
)(SchoolSettings);
export default SchoolSettings;
数据为:
{Id: 1, Name: "Our School", IsCompulsary: true}
答案 0 :(得分:1)
您需要将值字段添加到单选输入并对其值进行规范化,以便在更新商店之前将它们转换为布尔值:
<div>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
value={true}
normalize={value => value === 'true'}
/>{' '}
Yes
</label>
<label>
<Field
name="IsCompulsary"
component="input"
type="radio"
value={false}
normalize={value => value === 'true'}
/>{' '}
No
</label>
</div>