node.js - ant-design的组件报错 getFieldDecorator不是function
问题描述

到页面上展示:
报错:sampleInfoForm.js:205Uncaught TypeError: getFieldDecorator is not a function原因是什么呢??
PS.我是抄antdesign的Form 动态增减表单项的demo报错的
代码:
import React from ’react’import {render} from ’react-dom’let uuid = 0;//注意formClass的名称和var TalentUserAddForm = Form.create()(formClass);的TalentUserAddForm不能一样 let formClass = React.createClass({ componentWillMount() { this.props.form.setFieldsValue({ keys: [0], }); }, remove(k) { const { form } = this.props; // can use data-binding to get const keys = form.getFieldValue(’keys’); const nextKeys = keys.filter((key) => { return key !== k; }); // can use data-binding to set form.setFieldsValue({ keys: nextKeys, }); }, add() { uuid++; const { form } = this.props; // can use data-binding to get const keys = form.getFieldValue(’keys’); const nextKeys = keys.concat(uuid); // can use data-binding to set // important! notify form to detect changes form.setFieldsValue({ keys: nextKeys, }); }, render() { const { getFieldDecorator, getFieldValue } = this.props.form; console.log(getFieldDecorator); const formItems = getFieldValue(’keys’).map((k) => { return (<Form.Item {...formItemLayout} label={`good friend${k}:`} key={k}> <Input style={{ width: ’60%’, marginRight: 8 }} /> <Button onClick={() => this.remove(k)}>remove</Button></Form.Item> ); });return ( <p style={{display:'inline'}}><Modal visible={this.props.appointExpertPostFormReduce.get(’addModleVisible’)} onhandleRelease={this.handleSubmit} confirmLoading={this.props.appointExpertPostFormReduce.get(’confirmLoading’)} onCancel={this.props.appointExpertPostFormAction.onCancel} width={900} maskClosable={false} footer={[ <Button style={{backGround:'#000'}} key='btn' type='ghost' size='large' onClick={this.props.appointExpertPostFormAction.onCancel}> 取 消 </Button>, <Button key='submit' type='primary' size='large' onClick={this.handleSubmit}> 确 定 </Button>, ]}> <Form horizontal> {formItems}<Form.Item wrapperCol={{ span: 18, offset: 6 }}> <Button onClick={this.add} style={{ marginRight: 8 }}>add good friend</Button></Form.Item> </Form></Modal> </p> ); }, });var PostForm = Form.create()(formClass);module.exports = PostForm;
问题解答
回答1:你可以先试着在你你贴出的代码的第二行console.log(getFieldDecorator)一下,以确定这是一个实际存在的函数
另外是因为segmentfault贴图片太简单了还怎么的,全都喜欢截图贴代码,别人帮你改代码还要手打一遍吗?
回答2:getFieldDecorator 是 antd@2 引入的,确认下你使用的 antd 版本。
相关文章:
1. python - Pycharm调试代码进行列表遍历时,如何直接赋值指定元素2. 安装mysql,完成时提示的是用户名root,在终端查看版本时显示的不是root,请问这怎么解决3. python - pig latin问题 总是出现list/string index out of range4. 为什么HTML5规范中会包含一些和html无关的东西?如本地存储等。5. python - 如何解决程序运行太久之后被操作系统暂停的情况?6. mysql - 5w条数据的批量更新的sql7. javascript - sublime已经安装了babel插件和sublimelinter-jshint为什么还是显示es6语法错误?8. css3 - img垂直水平居中问题9. css3 - canvas在IOS8中不兼容。画不出来。10. 闯关的第二个问题的答案是错的吧?

网公网安备