ant-design / pro-components

🏆 Use Ant Design like a Pro!

Home Page:https://pro-components.antdigital.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ray0324 opened this issue · comments

提问前先看看:

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