首页 > 解决方案 > 如何添加切换按钮等操作来更改列表视图中某些字段的值?

问题描述

我想在 ListView 中添加可编辑字段,例如<BooleanInput />更改列表视图中某些字段的值。但是在阅读完文档后,我找不到任何想法。因为现在我对列表视图唯一能做的就是不可编辑的字段,例如<BooleanField />, <TextField />,...请提供一些建议或想法。太感谢了。

标签: javascriptreactjsreact-admin

解决方案


如果您想在列表中编辑这些条目,以下文章显示了如何将编辑放入列表中:https ://marmelab.com/blog/2019/01/09/react-admin-2-6.html#datagrid -扩展面板

const UserEdit = props => (
   <Edit 
       {...props}
       /* disable the app title change when shown */
       title=" "
    >
       <SimpleForm
           /* The form must have a name dependent on the record, because by default all 
           forms have the same name */
           form={`post_edit_${props.id}`}
       >
           <TextInput source="name" />
       </SimpleForm>
    </Edit>
);

const UserList = props => (
    <List {...props}>
       <Datagrid expand={<UserEdit />}>
           <TextField source="id" />
           <TextField source="name" />
           <TextField source="role" />
       </Datagrid>
  </List>
);

推荐阅读