Javascript 在“选择”中重新选择窗体对象
我已经创建了一个redux表单,我想在其中提交两个文本输入和一个select,其中所选项目是一个对象。但是,在提交后,我没有收到正确的对象,而是收到某种引用“[object]” 为选择对象渲染:Javascript 在“选择”中重新选择窗体对象,javascript,reactjs,redux-form,Javascript,Reactjs,Redux Form,我已经创建了一个redux表单,我想在其中提交两个文本输入和一个select,其中所选项目是一个对象。但是,在提交后,我没有收到正确的对象,而是收到某种引用“[object]” 为选择对象渲染: const renderSelectField = ({input, options, meta: {touched, error}}) => ( <select className='form-control' {...input}> <option><
const renderSelectField = ({input, options, meta: {touched, error}}) => (
<select className='form-control' {...input}>
<option></option>
{options.map(option =>
<option key={option.id} value={option}>{option.name}</option>
)}
</select>
)
<div className='form-group'>
<label>Category</label>
<div>
<Field name='category' component={renderSelectField} options={this.props.categories.categories}/>
</div>
</div>
以及提交的内容:
const renderSelectField = ({input, options, meta: {touched, error}}) => (
<select className='form-control' {...input}>
<option></option>
{options.map(option =>
<option key={option.id} value={option}>{option.name}</option>
)}
</select>
)
<div className='form-group'>
<label>Category</label>
<div>
<Field name='category' component={renderSelectField} options={this.props.categories.categories}/>
</div>
</div>
提前感谢您的帮助。您不能在
选项中使用对象作为值。一定是绳子。
像这样:
<option key={option.id} value={option.id}>{option.name}</option>
{option.name}
好吧,我试过了。问题是我无法到达或访问我想要的对象。如果我使用一个函数getCategoryById,我总是将set form submitted设置为false。您需要根据id在源数组中查找对象,该id将从值['category']
中获取。尝试方法查找数组的。