ant-design / pro-components

🏆 Use Ant Design like a Pro!
https://pro-components.antdigital.dev
MIT License
4.3k stars 1.36k forks source link

🧐[问题]renderFormItem中应该如何正确消费request返回的数据 #8512

Open ray0324 opened 4 months ago

ray0324 commented 4 months ago

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🧐 问题描述

renderFormItem中应该如何正确消费request返回的数据? 以下代码能正常运行 ,但是TS报错

💻 示例代码

    {
      title: '分配菜单',
      dataIndex: 'menus',
      valueType: 'option',
      hideInTable: true,
      hideInSearch: true,
      formItemProps: {
        tooltip: '分配菜单',
        rules: [
          {
            required: true,
            message: '选择菜单',
          },
        ],
      },

      request: async () => {
        console.log('request treeDataList:', treeDataList)
        return treeDataList;
      },

      renderFormItem: (schema, config, form) => {

        const onCheck: TreeProps['onCheck'] = (checkedKeysValue) => {
          form.setFieldsValue({ menus: checkedKeysValue });
        };

        const keys = form.getFieldValue('menus') || [];
        return (
          <ProFormItem
            colon={false}
            style={{ textAlign: 'right', marginBottom: 0 }}
          >
            <ProCard bordered style={{ borderColor: '#d9d9d9' }}>
              <Tree
                checkable
                onCheck={onCheck}
                checkedKeys={keys}
                treeData={config.option  ||[]}
                autoExpandParent={true}
              />
            </ProCard>
          </ProFormItem>
        );
      },
    },

🚑 其他信息

image