在组件BlocklyDrawer
中,我试图更改父组件的code
状态。我在onChange()
事件中执行此操作,调用了父组件handleCodex
的方法:
constructor(props) {
super(props);
this.state = {
code : "xxx",
};
this.handleCodex =
this.handleCodex.bind(this);
}
handleCodex(codex){
this.setState = ({
code: codex,
});
}
<BlocklyDrawer
tools={[INICIAR, MOVER, ATACAR]}
language = {Blockly.Javascript}
onChange={(code, workspace) => {
this.handleCodex(code);
}}
appearance={
{
categories: {
Agente: {
colour: '160'
},
},
}
}
>
尽管执行了方法handleCodex
,但code
状态不变。
答案 0 :(得分:1)
var elem = document.getElementById("SubmitBtn")
var click = new MouseEvent('click', {
view: window
});
elem.dispatchEvent(click);