我有一个阵列[a, b, c]
.我希望能够给此阵列的像的各元件之间的插入值:[0, a, 0, b, 0, c, 0]
.
我想这会是这样的,但我不能让它奏效.
for (let i = 0; i < array.length; i++) {
newArray = [
...array.splice(0, i),
0,
...array.splice(i, array.length),
];
}
Run Code Online (Sandbox Code Playgroud)
感谢你们对我的帮助!
我想防止e
并.
输入<input type="number"/>
. 没有 jQuery 或使用step
属性。我试过,pattern="[0-9]"
但它不起作用。
编辑:焦点键盘应该是数字键盘。
我正在尝试将我的状态对齐更改为:左对齐、居中对齐、右对齐或对齐,具体取决于<Icon />
我单击的对齐方式。但是,e.target.getAttribute('data-value')
正在返回null
。
当我更改<Icon icon="align-left" />
by 时left
,它正在工作。e.target.getAttribute('data-value')
正在返回数据值。
所以,我怎样才能改变我的状态,以左,右中心或我的点击自圆其说<Icon />
?
class TextStyleParams extends React.Component {
constructor(props) {
super(props);
this.onClickAlignment = this.onClickAlignment.bind(this);
this.state = {
textStyle: {
alignment: 'left',
...,
},
};
}
onClickAlignment(e) {
const { textStyle } = this.state;
const newTextStyle = {
...textStyle,
alignment: e.target.getAttribute('data-value'),
};
this.setState({ textStyle: newTextStyle });
this.props.updateTextStyle(newTextStyle);
}
render() {
const { textStyle } = this.state;
return (
<div>
<span role="button" onClick={this.onClickAlignment} …
Run Code Online (Sandbox Code Playgroud)