我试图执行与ReduxForm一个很简单的例子,我有渲染前两个功能,但功能之一调用其他的组件道具,但随后是不确定的。我试图绑定这个,但它仍然不认识它。Redux在渲染之前如何渲染一个数组的Field?
这里是我的代码:
import React, { Component } from 'react'
import { Field, FieldArray, reduxForm } from 'redux-form'
class Page4 extends Component {
constructor(props) {
super(props)
this.simpleField.bind(this)
}
simpleField(field) {
const { meta } = field
return (
<div className='form-group'>
<label>{field.label}</label>
<input
className='form-control'
{...field.input}
/>
</div>
)
}
// This function cannot reach the simpleField component
myFields(field) {
let optiosArray = [
{'label':'Option 1', 'value':'1'},
{'label':'Option 2', 'value':'2'}
]
return(
optionsArray.map((option, key) => {
<Field
label= {option.label}
value= {option.value}
name={option.value}
component={this.simpleField}
/>
})
)
}
render() {
return (
<div>
<FieldArray
name='test'
label='label'
component={this.myFields}
/>
</div>
)
}
}
const validate = (value) => {
const errors = ''
return errors
}
export default reduxForm({
validate,
form: 'Page4'
})(Page4)
你压痕关闭。你也说过你绑定了自己的功能,但是我看不到你做了这些。你不能通过函数内的'this'来访问你的实例,而无需绑定它们。 – trixn
嗨。编辑和修正:如果我绑定这个,我仍然会得到相同的错误。未捕获的TypeError:无法读取未定义的属性'simpleField' –
那么究竟是什么错误?你能否把它的确切文字添加到你的问题中? – trixn