鍍金池/ 問答/HTML5  PHP  HTML/ react ant design mobile的表單怎么用的,怎獲取數據報錯

react ant design mobile的表單怎么用的,怎獲取數據報錯

 submit=(e)=>{
        e.preventDefault();
        let value=this.props.form.getFieldValue('key')+this.props.from.getFieldValue('replytext');
        alert(value);
    }
    render() {
        const { getFieldProps } = this.props.form;
        return (
            <div className="createreply-container">
                <WhiteSpace />
                <WhiteSpace />
                <form onSubmit={this.submit}>
             <WingBlank>
                 <List renderHeader={() => '關鍵詞'}>
                     <InputItem
                         {...getFieldProps('key')}
                         placeholder="請輸入關鍵字"
                     />
                 </List>
             </WingBlank>
                <WhiteSpace />
              <WingBlank>
                  <List renderHeader={() => '回復內容'}>
                      <TextareaItem
                          {...getFieldProps('replytext', {
                              // initialValue: '請輸入回復內容...',
                          })}
                          placeholder="請輸入回復內容"
                          rows={5}
                          count={100}
                      />
                  </List>
              </WingBlank>
                <WhiteSpace />
                <WingBlank>
                    
                </WingBlank>
                <WhiteSpace size="lg"/>
                <WingBlank>
                    <Button type="primary"  onClick={this.submit}>完成</Button>
                    </WingBlank>
                </form>

部分代碼

出錯:
圖片描述

回答
編輯回答
心癌

摘抄三點ant design的文檔:

  1. [2.x] “Form 廢棄 getFieldProps,請使用 getFieldDecorator”,快速升級.
  2. 注意:使用 getFieldsValue getFieldValue setFieldsValue 等時,應確保對應的 field 已經用 getFieldDecorator 注冊過了。

3.validateFields 校驗并獲取一組輸入域的值與 Error,若 fieldNames 參數為空,則校驗全部組件 Function([fieldNames: string[]], options: object, callback: Function(errors, values))

validateFieldsAndScroll 與 validateFields 相似,但校驗完后,如果校驗不通過的菜單域不在可見范圍內,則自動滾動進可見范圍 參考 validateFields

2018年1月27日 02:15