react-admin:编辑未预先填充现有属性的表单

时间:2018-09-09 19:14:05

标签: javascript reactjs react-admin

我最近发现了react-admin。一切似乎都很好,但是我遇到一个问题,我找不到以下解决方案:

编辑现有记录时,所有输入字段均为空。提交空表格时-所有属性都为“空”。

这是我的代码:

// src/users.js
export const UserEdit = (props) => (
  <Edit title="Edit User" {...props}>
    <SimpleForm>
      <DisabledInput label="Id" source="id" />
      <TextInput source="first_name" />
      <TextInput source="last_name" />
    </SimpleForm>
  </Edit>
);

// App.js
const restClient = jsonAPIRestClient("http://localhost:3000/admin");

const App = () => (
  <Admin dataProvider={restClient}>
    <Resource name="users" list={UserList} edit={UserEdit}/>
  </Admin>
);

对于数据适配器,我正在使用jsonAPIRestClient。记录都已存储并在redux存储中可用。

有趣的是:DisabledInput这个ID出现在表单中。

我想念什么?

编辑:

package.json

{
  "name": "admin",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "aor-jsonapi-client": "^0.2.0",
    "prop-types": "^15.6.2",
    "react": "^16.5.0",
    "react-admin": "^2.3.0",
    "react-dom": "^16.5.0",
    "react-scripts": "1.1.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

修改2: 我刚刚发现,用户属性位于ca的编辑页面的输入字段中。 1/10秒。然后清除字段?!

编辑3: 这是导致此错误的redux动作:

RA/CRUD_GET_ONE_SUCCESS enter image description here

所以我想这是怎么回事,是数据提供程序将获取的单个资源错误地存储在redux存储中。这是正确的吗?

编辑4: 不幸的是,数据提供者似乎很糟糕。该存储库目前似乎无法维护。有一个PR旨在解决此问题。

https://github.com/moonlight-labs/aor-jsonapi-client/pull/6

2 个答案:

答案 0 :(得分:1)

问题是您使用的是Admin-On-Rest的旧版本React Admin的客户端aor-jsonapi-client

为了解决您的问题,我建议对React Admin使用相关的数据提供程序,例如:

有关更多信息,请参见React Admin上的documentation about data providers

答案 1 :(得分:0)

备用jsonapi客户端

我刚刚在这里找到了另一个可以正常工作的react-admin jsonapi客户端: https://github.com/henvo/ra-jsonapi-client

可以安装:

npm install ra-jsonapi-client
相关问题