jeudi 19 juillet 2018

Ember.set and Ember.setProperties gives different results

I ran into a problem in my Ember application where setting multiple properties using Ember.set and Ember.setProperties produced a buggy result in the latter. Constructed an exact scenario here.

HBS:

Name: <br>
Place: <br><br>

<button >this.setProperties({name:"Vignesh Raja",place:"Namakkal"})</button>

<br><br><br>

<button >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 Twiddle

In the above code, clicking first button (Ember.setProperties) gives Name: Vignesh Raja Place: Chennai, but clicking second (multiple Ember.set) gives Name: Vignesh Raja Place: Namakkal




Aucun commentaire:

Enregistrer un commentaire