如何在 react-admin 的另一个组件中显示 ImageInput src? [英] How to display ImageInput src in another component on react-admin?

查看:50
本文介绍了如何在 react-admin 的另一个组件中显示 ImageInput src?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-admin 并且我想在另一个组件中显示所选图像.

I'm using react-admin and I want to display the chosen image in another component.

我的编辑屏幕上已有图像.当我使用 ImageInput 选择一个新图像时,我想将它显示在我的 组件中,并使用新图像更改现有图像.

I have already an image on my Edit screen. When I select a new one with ImageInput, I'd like to display it in my <Poster /> component and change the existing image with a new one.

<Poster id="poster" {...props} source="card_image_path" 
label="resources.cards.fields.card_image_path" />

<ImageInput id="imageInput" source="images" accept="image/*">
  <ImageField source="src" title="title" />
</ImageInput>

推荐答案

传递任何组件,但在您的自定义组件中读取 record 道具.

Pass any component, but inside your custom component read the record props.

在这种情况下 ImageInput 发出 src 作为源

in this case ImageInput emits src as source

<ImageInput id="imageInput" source="images" accept="image/*">
<CustomComponent source="src" />
</ImageInput>

现在 CustomComponent 将接收 props.record

now CustomComponent will receive props.record

然后你只需读取 const {src} = this.props.record;

这篇关于如何在 react-admin 的另一个组件中显示 ImageInput src?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆