Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React admin:如何为GET\u LIST类型向数据提供程序传递更多参数_Reactjs_Parameters_React Admin_Dataprovider - Fatal编程技术网

Reactjs React admin:如何为GET\u LIST类型向数据提供程序传递更多参数

Reactjs React admin:如何为GET\u LIST类型向数据提供程序传递更多参数,reactjs,parameters,react-admin,dataprovider,Reactjs,Parameters,React Admin,Dataprovider,我想为“GET_LIST”类型向管理员的数据提供程序传递一个自定义参数 我在App.js中有类似的内容: <Admin dataProvider={dataProvider}> <Resource name="posts" list={PostList} myCustomAttr={"10"} /> <Resource name="users" list={UserList} myCustomAttr={"15"} /> </Adm

我想为“GET_LIST”类型向管理员的数据提供程序传递一个自定义参数

我在App.js中有类似的内容:

<Admin dataProvider={dataProvider}> 
    <Resource name="posts" list={PostList} myCustomAttr={"10"} /> 
    <Resource name="users" list={UserList} myCustomAttr={"15"} /> 
</Admin>
你可以

基本上,您拦截数据提供程序并根据类型和资源添加自己的行为:

if (type === 'GET_LIST') {
    params = {...params, myCustomParameter: 10};
}

return requestHandler(type, resource, params);

好的,我通过使用列表
过滤器
道具解决了这个问题:

<Admin dataProvider={dataProvider}> 
    <Resource name="posts" list={PostList} options={{ myCustomAttr: "10" }} /> 
    <Resource name="users" list={UserList} options={{ myCustomAttr: "15" }} /> 
</Admin>

谢谢你的回答。问题是除了资源之外,我还需要一个额外的参数。对于文档中的装饰器,类型为“UPDATE”,您可以使用“params”参数中的字段数据来查看如何操作。但是在“GET_LIST”的情况下,params中没有任何可识别的属性,只有排序和分页。我需要在获取数据时访问资源的数字道具集,如果我使用'Resource'参数,管理员的标题将显示一个数字,而不是像'Users'这样的名称。我编辑了我的答案。那不是你需要的吗?将自定义参数添加到参数中,然后继续调用原始dataProvider.Sure。但我该在哪里做呢?问题是,“10”值(在您的示例中)属于资源组件,一旦dataProvider被调用,我需要能够以某种方式传递它。我只需要一种方式将参数从资源组件传递到GET_LIST上的dataProvider,以指示服务器如何将json返回到LIST。我不清楚“值属于资源组件”是什么意思。它以何种方式属于资源,该值从何而来?
<Admin dataProvider={dataProvider}> 
    <Resource name="posts" list={PostList} options={{ myCustomAttr: "10" }} /> 
    <Resource name="users" list={UserList} options={{ myCustomAttr: "15" }} /> 
</Admin>
export const UserList = function(props) {
    return <List {...props} filter={{myCustomAttr:props.options.myCustomAttr}} >
        //...
    </List>
};
export default (type, resource, params) => {

    if (type == 'GET_LIST') {
       if (params.filter.myCustomAttr == '10') {
           //Do something
       }
    }
}