Javascript 从编辑组件访问模型

Javascript 从编辑组件访问模型,javascript,admin-on-rest,Javascript,Admin On Rest,我有以下编辑组件 const UserEdit = (props) => ( <Edit {...props}> <TabbedForm > <FormTab label="User Account"> <DisabledInput source="id" /> <TextInput source="email" /> <TextInput source

我有以下编辑组件

const UserEdit = (props) => (
  <Edit {...props}>
    <TabbedForm >
      <FormTab label="User Account">
        <DisabledInput source="id" />
        <TextInput source="email" />
        <TextInput source="password" type="password"/>
        <TextInput source="name" />
        <TextInput source="phone" />
        <SelectInput source="role" optionValue="id" choices={choices} />
      </FormTab>
      <FormTab label="Customer Information">
        <BooleanInput label="New user" source="Customer.is_new" />
        <BooleanInput label="Grandfathered user" source="Customer.grandfathered" />
      </FormTab>
    </TabbedForm >
  </Edit>
);
第二个FormTab客户信息我只需要在用户模型具有与JSON相关联的某些信息时显示,如下所示:

{
   id: <int>,
   name: <string>,
   ....
   Customer: {
       is_new: true,
       grandfathered: true,
   }
}
我想知道,在这种情况下,我是否可以访问模型信息,如果客户密钥存在,并且具有信息,以便能够渲染或不渲染模型

我有点迷茫于全球重演状态。我知道数据处于状态,因为我已经用Redux工具对其进行了调试。我试图查看这个.props,但找不到任何东西可以访问全局状态


谢谢。

如果您在构建表单时需要该对象,可以将其连接到redux应用商店

import { connect } from 'react-redux';

// this is just a form, note this is not being exported
const UserEditForm = (props) => {
    console.log(props.data); // your object will be in props.data.<id>
    let customFormTab;
    const id = props.params.id;

    if (typeof props.data === 'object' && && props.data.hasOwnProperty(id)) {
        if (props.data[id].something) {
            customFormTab = <FormTab>...;
        }
    }

    return <Edit {...props}>
          <Formtab...
          {customFormTab}
    </Edit>;
}

// this is your exported component
export const UserEdit = connect((state) => ({
    data: state.admin.User.data
}))(UserEditForm);

PS:我不确定这是否是一个好的或期望的解决方案,希望有人会纠正我,如果我做的事情不是按照redux或admin on rest的设计

我想这会起作用,因为我可以访问Redux状态,在那里我可以看到Redux表单等。谢谢!