【问题标题】:How to add custom action in react-admin如何在 react-admin 中添加自定义操作
【发布时间】:2021-05-09 06:52:49
【问题描述】:

我使用 react-admin,并且需要在我的列表视图中添加一个自定义按钮,该按钮将导航到特定的 API。

我的问题:

  1. 如何创建按钮?我应该在清单上写什么?
  2. 如何将其导航到 API?

谢谢

【问题讨论】:

    标签: react-admin


    【解决方案1】:

    我的解决方法:

    1. 创建自定义按钮:

       import Button from '@material-ui/core/Button';
       import { TopToolbar } from 'react-admin';
      
       const PostShowActions = ({ basePath, data, resource }) => (
       <TopToolbar>
           {/* Add your custom actions */}
           <Button color="primary" onClick={customAction}>Custom Action</Button>
       </TopToolbar>
       );
      
       export const PostList = (props) => (
       <List actions={<PostShowActions />} {...props}>
           ...
       </List
       );
      
    2. 将其导航到 API: 我这样实现了 customAction:

      const genarte = () => {
          const httpClient = fetchUtils.fetchJson;
          const apiUrl = "your API";
          httpClient(`${apiUrl}`,{method: "POST"}).then(({ json }) => ({
                      data: json,
                    })
      
          ); };
      

    我知道它不会将页面导航到外部链接,只会发出 http 请求, 但现在我的需要没问题。

    如果您对如何将页面导航到外部链接有任何意见或想法,我会很高兴

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 2023-03-08
      • 1970-01-01
      • 2021-06-25
      • 2022-10-04
      相关资源
      最近更新 更多