Hi我想在v3中使用两个数据提供程序,使用一个superDataProvider。并根据资源的名称决定。我遵循了同样的例子,但没有成功(我也尝试了使用dataProviderFactory的演示方式(
import jsonServerProvider from 'ra-data-json-server';
import restProvider from 'ra-data-simple-rest';
const dataProviderRest = restProvider('https://myapi.com');
const dataProviderJson = jsonServerProvider('https://jsonplaceholder.typicode.com');
const superDataProvider = (type: any, resource: any, params: any) => {
if (resource === 'tags') {
return dataProviderRest;
}
return dataProviderJson;
}
export default superDataProvider;
文档说dataProvider必须具有以下方法:
const dataProvider = {
getList: (resource, params) => Promise,
getOne: (resource, params) => Promise,
getMany: (resource, params) => Promise,
getManyReference: (resource, params) => Promise,
create: (resource, params) => Promise,
update: (resource, params) => Promise,
updateMany: (resource, params) => Promise,
delete: (resource, params) => Promise,
deleteMany: (resource, params) => Promise,
}
所以,我认为可以使用这样的东西:
import jsonServerProvider from 'ra-data-json-server';
import restProvider from 'ra-data-simple-rest';
const dataProviderRest = restProvider('https://myapi.com');
const dataProviderJson = jsonServerProvider('https://jsonplaceholder.typicode.com');
export const superDataProvider = {
...dataProviderJson, // Preserve methods that are not extended
update: (resource, params) => {
if (resource === 'tags') {
return dataProviderRest.update(resource, params);
}
return dataProviderJson.update(resource, params);
}
}