0

我需要通过Edit两种方式自定义组件:

  • 添加自定义按钮,但不是在上面板(带有“列表”和“刷新”按钮),而是在组件的底部(在默认的“保存”按钮旁边)。
  • 在默认的“保存”按钮单击时关闭重定向(使其只是保存并留在页面上)。

我如何实现这一目标?

4

1 回答 1

1

我遇到了这个没有答案的问题。因为我最近自己做了这样的事情,所以我将在这里分享我是如何做到的。我在 rest 1.4.0 btw 上使用管理员。

所以,在你的<Edit>组件上,添加这个toolbar={<MyCustomToolbar />}. 然后创建一个自定义工具栏,其中包含您的按钮。在按钮上,您可以使用redirect重定向到另一个页面。

代码示例:

import { SaveButton, Toolbar, TextInput, Edit, SimpleForm  } from 'admin-on-rest';

const MyToolbar = props => 
 <Toolbar {...props} >
   <SaveButton label="Save & to dashboard" redirect="/" />
   .. more buttons here..
 </Toolbar>;


export const EditForm = (props) => (
<Edit title="Edit" {...props}>
    <SimpleForm toolbar={<MyToolbar />}>
        <TextInput source="company_website" type="url" />
        <TextInput source="address_street" />
        <TextInput source="address_zip" />
        <TextInput source="address_unitnr" />
        <TextInput source="address_city" />
    </SimpleForm>
</Edit>
);

希望这可以帮助!

于 2018-04-08T08:35:48.520 回答