我想为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>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的表单中使用此组件:
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'}]} /> …
Run Code Online (Sandbox Code Playgroud) 我有一个源多维数组.看起来像:
var arr = [];
arr[1] = [];
arr[2] = [];
arr[3] = [];
arr[1][1] = "11";
arr[1][2] = "12";
arr[1][3] = "13";
arr[2][1] = "21";
arr[2][2] = "22";
arr[2][3] = "23";
arr[3][1] = "31";
arr[3][2] = "32";
arr[3][3] = "33";
Run Code Online (Sandbox Code Playgroud)
我需要使用ES6功能将其转换为平面阵列.结果必须如下所示:
var res = [
{ col:1, row:1, val:"11"},
{ col:1, row:2, val:"12"},
{ col:1, row:3, val:"13"},
{ col:2, row:1, val:"21"},
{ col:2, row:2, val:"22"},
{ col:2, row:3, val:"23"},
{ col:3, row:1, val:"31"},
{ col:3, row:2, val:"32"},
{ col:3, …
Run Code Online (Sandbox Code Playgroud)