我正在尝试创建一个redux表单(使用redux-form),可以动态创建自己的输入.我无法弄清楚如何让redux-form知道已经创建的新字段.是否有可能动态更改redux-form在表单组件本身中传递的字段?我在想这个错吗?这是我正在使用的.
class AddCustomer extends Component {
render() {
class Form extends Component {
constructor(props, context) {
super(props, context)
this.state = {
inputsToAdd: []
};
}
handleAddInput() {
let inputsToAdd = this.state.inputsToAdd.slice();
inputsToAdd.push(this.state.inputsToAdd.length);
this.setState({ inputsToAdd });
}
submitForm(data) {
console.log(data)
this.setState({inputsToAdd: []});
this.props.dispatch(initialize('addCustomer', {}))
}
render() {
const { fields, handleSubmit } = this.props;
return (
<div>
<form onSubmit={handleSubmit(this.submitForm.bind(this))}>
<Input type='text' label='Company name' {...fields['companyName']}/>
<Input type='email' label='Admin user email' {...fields['adminEmail']}/>
</form>
{this.state.inputsToAdd.map((element, index) => {
return (
<Input key={index} type='text' /> …Run Code Online (Sandbox Code Playgroud) 我无法在react-redux应用程序中获取react-bootstrap来做这件事.我有一个看起来像这样的组件:
import React, { Component, PropTypes } from 'react';
import { Button } from 'react-bootstrap';
class Foo extends Component {
constructor( props, actions ) {
super(props, actions);
}
render() {
const { people } = this.props;
return(
<ul>
{people.map(person => {
return(
<div key={person}>
<li>{person.name}</li>
<Button bsStyle="success" onClick={ () => removePerson(person) }>Remove</Button>
</div>
)
})}
</ul>
)
}
}
export default Foo;Run Code Online (Sandbox Code Playgroud)
但react-bootstrap并没有为元素设置样式.对我缺少什么的想法?谢谢!