{this.getFields().map((field, i) => {{checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)}})}
您的代码不会返回任何内容,因为您在函数语法中使用了花括号.要么这样做
{this.getFields().map((field, i) =>{checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)})}
要么
{this.getFields().map((field, i) => { return ({checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)}); })}
对于干净的代码,我会将map函数保留在JSX标记之外:
render() { let values = this.state.fieldValues; const checkType = this.checkType.bind(this); const fields = this.getFields().map((field, i) =>{checkType(field.type, field.options, field.placeholder, field.name, this.handleUpdatedValue.bind(this), field.defvalue, field.index)}); return(); }{this.props.header}
{fields}