我在我的应用程序中遇到了一个问题,Ember
即使用设置多个属性Ember.set
并Ember.setProperties
在后者中产生了错误的结果。在这里构建了一个确切的场景。
哈佛商学院:
Name: {{name}}<br>
Place: {{place}}<br><br>
<button {{action "modifyTogether"}}>this.setProperties({name:"Vignesh Raja",place:"Namakkal"})</button>
<br><br><br>
<button {{action "modifySeperately"}}>this.set("name","Vignesh Raja");<br>this.set("place","Namakkal");</button>
<br><br><br>
When set seperately, we get the latest value - {name:"Vignesh Raja", place:"Namakkal"}<br>
When set together, we get the latest value from the observer- {name:"Vignesh Raja", place:"Chennai"}<br>
<br>
<br>
JS:
import Ember from 'ember';
export default Ember.Controller.extend({
name:"Vignesh",
place:"Nmkl",
handleName1 : function(){
this.set("place","Chennai");
}.observes("name"),
actions:{
modifyTogether:function(){
this.setProperties({name:"Vignesh Raja",place:"Namakkal"})
},
modifySeperately:function(){
this.set("name","Vignesh Raja");
this.set("place","Namakkal");
}
}
});
在上面的代码中,单击第一个按钮 ( Ember.setProperties
) 给出Name: Vignesh Raja Place: Chennai
,但单击第二个 ( 多个Ember.set
) 给出Name: Vignesh Raja Place: Namakkal