所以我有一个form
,其中包含有关后端两个表的数据:
通常,update
中的react-admin
方法很简单,但在这种情况下并非如此。因此,我从zone
和area
表中获取了数据并将其放在一种形式中。
我还根据saveButton
更改了values
来调整表格react-admin documentation的格式,因此,在提交之前,此值是正确的表格。
挑战是...当我以某种方式单击onClick
中的按钮时,我需要在2个端点上执行2个update
调用update
来执行dataProvider
。我本想在这种情况下使用redux-saga
,但还没有运气。
欢迎任何想法,提示或代码示例。
这里有两种选择:
dataProvider.updates
。另外,您可以直接fetch()
以获得更大的灵活性。 (您可能希望使用React.useCallback
和async
以获得更好的性能)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} />; };
以上其中一项应带您去...