我的react-admin面板的服务器端出现错误“ url不正确”

时间:2019-12-05 11:00:59

标签: reactjs rest api frontend react-admin

我在react-admin面板中工作,需要在Providers的基础上显示Rest API的“ Drivers”数据。 但问题是驱动程序api端点是/ providers / goods / drivers 我正在使用代码在Providers_id的基础上获取数据

父母

<Tab label={"Drivers"}>               
   <TestShowDrivers/> 
</Tab>

孩子

class ShowUserToProvider extends Component {
     constructor(props) {
         super(props);
         this.state = {
             url: ''
         }
     }
     componentDidMount() {
         let path = this.props.record.serviceType;
         let url = '';
         if (path == "GOODS_DELIVERY") {
             url = "providers/goods/drivers"
         } else if (path == "FOOD") {
             url = "providers/food/drivers"
         } else if (path == "GROCERY") {
             url = "providers/grocery/drivers"
         } else if (path == "WATER") {
             url = "providers/water/drivers"
         } else if (path == "GAS") {
             url = "providers/gas/drivers"
         } else if (path == "CHARITY") {
             url = "providers/charity/drivers"
         } else if (path == "REPAIR") {
             url = "providers/repair/drivers"
         }
         this.setState({
             url: url
         })
     }
     render() {
         const {url} = this.state;
         console.log(url);
         return (

             <Tab {...this.props}>
                 <ReferenceManyField reference={url} target={"id"}  {...this.props}>
                     <Datagrid>
                         <TextField source={"name"}/>
                     </Datagrid>
                 </ReferenceManyField>
             </Tab>

         );
     }
}
 export default ShowUserToProvider;

我还为App.js组件添加了资源

<Admin dataProvider={OurClient(SERVER_IP)} />
     <Resource name={"providers/goods/drivers"}/>
     <Resource name={"providers/repair/drivers"}/>
     <Resource name={"providers/food/drivers"}/>
     <Resource name={"providers/grocery/drivers"}/>
     <Resource name={"providers/water/drivers"}/>
     <Resource name={"providers/gas/drivers"}/>
     <Resource name={"providers/charity/drivers"}/>
     <Resource name={"providers/repair/drivers"}/>
</Admin>

但未能解决端点正确的问题...

请帮助我

0 个答案:

没有答案