在react admin中,如果您有FileInput,它需要一个子字段,并将文件URL存储在该子字段内。因此,例如
{
"photo": {
"url": "https://url-to-image.com"
}
}
和相应的react admin代码是
<FileInput source='photo' label='Photo' placeholder={<p>Drop your image file here</p>}>
<ImageField source='url' title='title' />
</FileInput>
我想上载到名为photoUrl
的单个键而不是嵌套对象photo.url
,它看起来像这样:
{
"photoUrl": "https://url-to-image.com"
}
我该怎么做?当我省略ImageField时,我得到一个错误,期望有一个孩子。我尝试将image =“ field”的source =“”留为空白,但仍会产生错误。
有什么想法吗?
尝试将解析和格式函数传递给FileInput属性
<FileInput
source='photoUrl'
label='Photo'
placeholder={<p>Drop your image file here</p>}
parse={p => p.url}
format={url => ({url})}
>
<ImageField source='url' title='title' />
</FileInput>
https://marmelab.com/react-admin/Inputs.html#transforming-input-value-tofrom-record