dimanche 28 février 2016

Ember.js 2.3 implement @each.property observer on a HasMany relationship?

Say I have a hasMany relationShip Procedure => hasMany Steps, with async:true, and I have a Procedure Component (on the procedure route) called procedure-main, which lists the steps as so:

{{each procedure.steps as |step| }}
 {{step.title}}
{{/each}}

I need to observe a property on each step (say, stepStatus) on change to the stepStatus on any of the steps. In Ember 1.7, I had something like this on the procedure controller:

stepsStatusObserver: function(){
...
}.observes('steps.@each.stepStatus')

This was fired on change of stepStatus on any on the steps, and whatever I had in this function was fired whenever the status changed as well. However, in Ember2.3, I cannot implement this. I have tried with

stepsStatusObserver: Ember.observer('steps.[].stepStatus', function(){
...
})

but this only fires once when the steps are being listed on the page. When I change the status of one step to a new value, the function is never fired.

How can I replicate this functionality in Ember 2.3?

Note: In my use case, I cannot rely on manually setting off the function inside the observer on the click of a button as it must automatically fire if the stepStatus property was changed on any step.




Aucun commentaire:

Enregistrer un commentaire