美文网首页
ant 自定义表单组件

ant 自定义表单组件

作者: LenHong | 来源:发表于2019-08-07 11:07 被阅读0次

表单如果使用修饰器 getFieldDecorator 需要在自定义组件调用 this.props.onChange
表单如果使用 resetFields 需要在自定义组件中设置 value={this.props.value}

...
render() {
    const { deptListOptions, onChange, value } = this.props;
    return (
      <TreeSelect
        placeholder="请选择"
        style={{ width: '100%' }}
        loadData={this.loadTreeNode}
        dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}

        //实现外部的 resetFields 方法
        value={value} 

        //实现外部的 getFieldDecorator 方法
        onChange={onChange}
      >
        {this.renderTreeNodeOptions(deptListOptions)}
      </TreeSelect>
    );
  }
...

自定义表单组件只要满足以下条件,即可与 Form 组件一起使用

  • 提供受控属性 value 或其它与 valuePropName的值同名的属性。

  • 提供 onChange 事件或 trigger 的值同名的事件。

  • 支持 ref:

参考:https://ant.design/components/form-cn/#components-form-demo-customized-form-controls

相关文章

网友评论

      本文标题:ant 自定义表单组件

      本文链接:https://www.haomeiwen.com/subject/uqzwdctx.html