我正在单个组件中创建多个表单,并使用我定义表单的 redux 存储来初始化它们name属性中的<form>
元素,而不是在reduxForm()
助手,记录在这里......
如何在页面上多次嵌入相同的 redux-form ? https://stackoverflow.com/questions/37456526/how-to-embed-the-same-redux-form-multiple-times-on-a-page/37464048#37464048
我正在从“列表”对象创建表单并将其传递给我的组件mapStateToProps()
。我正在尝试设置表单的初始值initialValues={}
,但是 Redux Form 会产生以下错误,并要求在reduxForm()
帮手...
1)失败的道具类型:道具form
已按要求标记为Form(ItemInfo)
,但其值为undefined
.
2)未知道具initialValues
在标签上。从元素中删除此道具。
这似乎与这里提到的问题相似......
https://github.com/erikras/redux-form/issues/28 https://github.com/erikras/redux-form/issues/28
import _ from 'lodash';
import React, { Component } from 'react';
import { reduxForm, Field } from 'redux-form';
import { connect } from 'react-redux';
import * as actions from '../../../actions';
import {Col} from 'react-grid-system';
import RaisedButton from 'material-ui/RaisedButton';
class ItemInfo extends Component {
renderSingleItem(item){
let theItem = _.map(_.omit(item, '_id'), (value,field) => {
return (
<div key={field}>
<label>{field}</label>
<Field component="input" type="text" name={field} style={{ marginBottom: '5px' }} />
<div className="red-text" style={{ marginBottom: '20px' }}>
</div>
</div>
);
});
return theItem || <div></div>;
}
renderItemInfo() {
if (this.props.listing.listing !== undefined) {
let theItems = _.map(this.props.listing.listing.items, item => {
return (
<Col key={item._id} md={3}>
<form form={`editItemInfo_${item._id}`} initialValues={item}>
{this.renderSingleItem(item)}
<RaisedButton secondary={true} label="Remove Item"/>
<RaisedButton primary={true} label="Update Item"/>
</form>
</Col>
);
});
return theItems || <div></div>;
}
}
render() {
return (
<div className="row">
{this.renderItemInfo()}
</div>
);
}
}
function mapStateToProps({listing}) {
return { listing };
}
ItemInfo = reduxForm({
fields: ["text"],
enableReinitialize: true
})(ItemInfo)
ItemInfo = connect(mapStateToProps,actions)(ItemInfo)
export default ItemInfo
这是返回“列表”对象的示例......
{ _id: 59b5eebd33a3a833b6ac1386,
_user: 59aff09a11011f0cfd8d7666,
location: 'nother',
availability: 'jhkvljh',
price: 9860,
__v: 0,
items:
[ { equipmentType: 'kbj;kj',
make: ';jb',
model: ';;jb',
watts: 9860,
bulb: 'kjbkj',
condition: 'kjbkjb',
_id: 59b5eebd33a3a833b6ac1387 },
{ condition: 'houy',
bulb: 'jhg',
watts: 8907,
model: 'mode',
make: 'maker',
equipmentType: 'smoquip',
_id: 59b5f9cf13b37234ed033a75 } ] }
感谢您的帮助!