React-Admin:如何从[

问题描述 投票:0回答:1

所以我有一个form,其中包含有关后端两个表的数据:

  • 区域
  • 区域

通常,update中的react-admin方法很简单,但在这种情况下并非如此。因此,我从zonearea表中获取了数据并将其放在一种形式中。

我还根据saveButton更改了values来调整表格react-admin documentation的格式,因此,在提交之前,此值是正确的表格。

挑战是...当我以某种方式单击onClick中的按钮时,我需要在2个端点上执行2个update调用update来执行dataProvider。我本想在这种情况下使用redux-saga,但还没有运气。

欢迎任何想法,提示或代码示例。

javascript react-admin
1个回答
0
投票

这里有两种选择:

  • 单击两次即可调用两个dataProvider.updates。另外,您可以直接fetch()以获得更大的灵活性。 (您可能希望使用React.useCallbackasync以获得更好的性能)
export const SaveButton = ({
  basePath = '',
  label = 'Save',
  record,
  ...rest
}) => {
  const handleClick = () => {
    if (record !== undefined) {
      // first call -> Zone
      async () => await dataProvider.update(...);
      // Second call -> Area
      async() => await dataProvider.update(...);
    }
  };
  return <Button label={label} onClick={handleClick} {...rest} />;
};
  • 声明两个函数以分别调用每个调用dataProvider.update。如果您打算在同一clickEvent]中触发其他任何component之后执行相同的调用,则将为您提供灵活性
export const SaveButton = ({
  basePath = '',
  label = 'Save',
  record,
  ...rest
}) => {
  const handleClick = () => {
    if (record !== undefined) {
      // first call -> Zone
      handleZoneCall();
      // second call -> Area
      handleAreaCall();   
    }
  };

  const handleZoneCall = async () => await dataProvider.update(...);
  const handleAreaCall = async() => await dataProvider.update(...);

  return <Button label={label} onClick={handleClick} {...rest} />;
};

以上其中一项应带您去...

© www.soinside.com 2019 - 2024. All rights reserved.