Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[问题] profrom中有两个组件,A组件是下拉框,下拉值是:输入框、下拉框,B组件展示是根据A组件选择的值。比如,A组件选择的值是:下拉框时,B组件展示的就是下拉框组件 #8736

Open
Lziam opened this issue Sep 21, 2024 · 1 comment

Comments

@Lziam
Copy link

Lziam commented Sep 21, 2024

提问前先看看:

🧐 问题描述

💻 示例代码

`

<ProFormSelect
width="sm"
label="字段类型"
name={item.configType}
initialValue={ item.configType }
options={[
{
label: '输入框',
value: 'input'
},{
label: '下拉框',
value: 'select'
},{
label: '日期选择',
value: 'select_time_ymd'
},{
label: '时间选择',
value: 'select_time_hms'
},{
label: '年月日时分秒',
value: 'select_time_all'
},{
label: '未知类型',
value: NaN
},
]}
/>

              <ProFormText
                width="sm"
                label="默认值"
                name={`${[item.id](http://item.id/)}.defaultValue`}
                initialValue={item.value}
              />
`

🚑 其他信息

@Lziam Lziam changed the title 🧐[问题] profrom中有两个组件,A组件是下拉框,下拉值是:输入框、下拉框,B组件展示是根据A组件选择的值。比如,A组件选择的值是:下拉框时,B组件展示的就是下拉框 🧐[问题] profrom中有两个组件,A组件是下拉框,下拉值是:输入框、下拉框,B组件展示是根据A组件选择的值。比如,A组件选择的值是:下拉框时,B组件展示的就是下拉框组件 Sep 21, 2024
@Lziam
Copy link
Author

Lziam commented Sep 22, 2024

我的表单数据是循环出来的,代码如下,取出来的configType 是个undefined: <ProFormSelect
width="sm"
label="字段类型"
name={${item.id}.configType}
initialValue={ item.configType }
options={[
{
label: '输入框',
value: 'input'
},{
label: '下拉框',
value: 'select'
},{
label: '日期选择',
value: 'select_time_ymd'
},{
label: '时间选择',
value: 'select_time_hms'
},{
label: '年月日时分秒',
value: 'select_time_all'
},{
label: '未知类型',
value: NaN
},
]}
/>

      <ProFormDependency
        name={[`${item.id}.configType`]}
      >
        {({ configType }) => {
          console.log('configType is :', configType)
          if (configType === 'input') {
            return (
              <ProFormText
                width="sm"
                label="默认值"
                name={`${item.id}.defaultValue`}
                initialValue={item.value}
              />
            );
          } else if (configType === 'select') {
            return (
              <ProFormSelect
                width="sm"
                label="默认值"
                name={`${item.id}.defaultValue`}
                initialValue={item.value}
                options={options} // 确保这里定义了 options 变量
              />
            );
          }
          return (
            <ProFormText
              width="sm"
              label="默认值"
              name={`${item.id}.defaultValue`}
              initialValue={item.value}
            />
          ); // 如果不是输入框或下拉框,不渲染任何组件
        }}
      </ProFormDependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant