zoukankan      html  css  js  c++  java
  • react antd

    react 的 antd框架中 form使用需注意:

    1、不能用state改变下拉框、输入框等组件的值,因为 经过 getFieldDecorator 包装的控件,表单控件会自动添加 value(或 valuePropName 指定的其他属性) onChange(或 trigger 指定的其他属性),数据同步将被 Form 接管值。要用setFieldsValue({key:value});

    2、比如修改页面使用form 用到下拉框Select时,要给select加上lableInValue={true}属性,相应的setFieldsValue 的value也必须换成{key:“”,value:""}的形式

    3、子组件form表单自定义的方法,父组件里通过this.refs.someName.somoeFunction是获取不到该方法的,要用wrappedComponentRef:

    <From wrappedComponentRef={(inst) => this.formRef = inst}/>

    this.formRef.somoeFunction

    因为源码中

    class Form extends React.Component { ... }
    
    // deprecated
    const EnhancedForm = createForm({ withRef: true })(Form);
    <EnhancedForm ref="form" />
    this.refs.form.refs.wrappedComponent // => The instance of Form
    
    // Recommended
    const EnhancedForm = createForm()(Form);
    <EnhancedForm wrappedComponentRef={(inst) => this.formRef = inst} />
    this.formRef // => The instance of Form

     4.mobx 和from一起使用,如果是用修饰器写法,要这样写:

    @Form.create()
    @observer

    先创建form再去监听。

  • 相关阅读:
    洛谷P1036 选数
    洛谷 P1009 阶乘之和
    codevs 4165 ​高精度求阶乘
    codevs 1553 互斥的数
    P2421 A-B数对(增强版)
    51nod 1081 子段求和
    codevs 3054 高精度练习-文件操作
    无聊写的高精的斐波那契数列
    51nod 1347 旋转字符串
    51nod 1212 无向图最小生成树(Kruskal模版题)
  • 原文地址:https://www.cnblogs.com/duanlibo/p/8890955.html
Copyright © 2011-2022 走看看