我的react组件中包含以下代码
export default class CalculatedMeasure extends React.Component {
constructor(props) {
super(props);
let formulaInput = [
"(", "(", "(", "2", "+", "3", ")", "*", "3", ")", "+", "(", "12", "/" ];
this.state = {
formulaArray: formulaInput,
selectedIndex: size(formulaInput)? size(formulaInput) - 1: 0
}
this.handleDeleteCalculatorValues = this.handleDeleteCalculatorValues.bind(this);
}
handleDeleteCalculatorValues(event = {}) {
const { keyCode } = event;
let keyPressCodes = [ON_DELETE_KEY_PRESS,ON_BACKSPACE_KEY_PRESS];
if (isNil(keyCode) || includes(keyPressCodes,keyCode)) {
if(isEmpty(this.state.formulaArray)){
return false;
}
let index = this.state.selectedIndex;
if(!isJsonObject(this.state.formulaArray[index]) && !isOp(this.state.formulaArray[index])){
const newArray = this.state.formulaArray;
newArray[index] = this.state.formulaArray[index].slice(0, -1);
if(newArray[index].length == 0){
this.setState({
selectedIndex: index - 1
})
}
this.setState({
formulaArray: newArray
});
}
else{
this.state.formulaArray.splice(index);
this.setState({
selectedIndex: index - 1,
})
}
}
}
render(){
return()
<div ref={this.calculatedMeasureRef} tabindex="10" id="calculated-measure-container" className="col-md-12" onKeyDown={this.handleDeleteCalculatorValues}>
<div>{this.state.formulaArray}</div>
</div>
}
}
当我尝试使用BackSpace键和Delete键删除公式数组中的元素时,它们在Chrome中运行良好,但这些键在IE中无法正常工作。
在IE中,当按下BackSpace键时,窗口将移至上一个选项卡,有时不执行任何操作