Uncaught TypeError: Cannot read properties of undefined (reading 'length')

135 阅读1分钟

select多选,form表单setFieldsValue数组,但是报错

以下是我的form表单,无论是在componentDidMount还是initialValue数值为数组都会报错 各种注释发现,是因为options未在初始状态给空数组,才会导致组件报错


constructor(props: any) {
    super(props);
    this.state = {
        isShowHrStaffIds: false,
        confirmLoading: false,
        webAppUsers: [],//////一定一定要给初始值!!!!!!!!!
    }
}

<IrsForm
    labelCol={{ span: 6 }}
    wrapperCol={{ span: 12 }}
    formItemCol={{ md: 24 }}
    onValuesChange={this.onValuesChange}
    formRef={this.getFormRef}
>
    <Item
        name="viewAuthorityStaffIds"
        component='multiple'
        label={'允许查看人员'}
        rules={[{
            required: true,
            message: '允许查看人员不能为空',
        }]}
        options={webAppUsers}
        componentProps={{
            width: 276,
        }}
        initialValue={[IrsDataStorage.getLocal('USER_ME')?.staffId]}
        //这里会报错
    />
</IrsForm>