【发布时间】:2020-09-27 14:46:53
【问题描述】:
我正在使用 react-admin 和 react-rrule-generator (https://github.com/Fafruch/react-rrule-generator)。使用 rrule 小部件时创建/添加记录工作正常。但是每当我尝试编辑记录时,小部件应该根据记录的值自动填充其值。但该值始终是小部件本身提供的默认值。这是我的代码:
main_file.jsx
export const JobCreate = (props) => {
return (
<Create {...props}>
<SimpleForm>
<CustomRRuleInput name="recurrency" label="Recurrency" />
</SimpleForm>
</Create>
)
}
recurrency_field.jsx
export const CustomRRuleInput = (props) => {
const {
input: { onChange },
meta: { touched, error },
} = useInput(props)
return (
<Labeled label={props.label}>
<RRuleGenerator
onChange={onChange}
name={props.name}
/>
</Labeled>
)
}
如果我在RRuleGenerator 组件中添加value={props.record.recurrency},我无法更改值,因为我固定/硬编码了它的值,即使我尝试更改它们也是恒定的。如果这个小部件有一个名为defaultValue 的道具,那么它就会成功!
我怎样才能做到这一点?
【问题讨论】:
标签: reactjs react-admin recurrence rrule