状态看起来像这样
{
ownRecipe: {name:""}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要更改名称属性,这不起作用
this.setState({ownRecipe[name]:"Pineapple pizza"});
Run Code Online (Sandbox Code Playgroud)
这可行,但也许有更好的方法?
let ownRecipeCopy = {}
for(let key in this.state.ownRecipe){
ownRecipeCopy[key] = this.state.ownRecipe[key];
}
ownRecipeCopy.name = e.target.value;
this.setState({ownRecipe: ownRecipeCopy});
Run Code Online (Sandbox Code Playgroud)
编辑:谢谢大家的回答
我需要能够单击背景并获取单击的位置。
我尝试向舞台添加一个事件侦听器,如下所示
app.stage.interactive = true;
app.stage.on('click', function(){
console.log('hello');
})Run Code Online (Sandbox Code Playgroud)
但只有当我单击舞台内的元素而不是背景本身时它才有效。
我是否需要制作一个精灵作为背景,如果需要,我如何设置其背景颜色并确保它位于所有其他元素下方?