【发布时间】:2017-03-01 08:50:48
【问题描述】:
我想为 redux-form V6 创建自定义组件。它看起来像按钮切换器。
组件
import React, { Component } from 'react';
export default class ButtonSwitcher extends Component{
// props.buttons [{text: "Btn Text", value: "BtnValue"}]
render (){
return (
<div className="btn-group" style={{verticalAlign: 'top'}}>
{this.props.buttons.map((button, index)=>(
<a href="#" key={index} onClick={this.props.onChange} className={(this.props.value === button.value) ? 'active btn btn-default' : 'btn btn-default'}>{button.text}</a>
))}
</div>
);
}
}
我在我的表单中使用这个组件:
const renderButtonSwitcher = props => {
return (
<ButtonSwitcher value={props.input.value} onChange={props.input.onChange} buttons={props.data} />
)
};
<Field name="PODType" component={renderButtonSwitcher} data={[{text: '%', value: 'percent'}, {text: '$', value: 'amount'}]} />
如何获得选定的按钮值? 我在 redux-form V6 中找不到任何高级示例
onSubmit(data) {
console.log("onSubmit", data);
}
onSubmit 显示空数据对象
【问题讨论】:
标签: reactjs redux-form