I have an ArrayController
which observes changes of a specific property of each model. I use the .observes('[email protected]')
for that purpose:
App.ListController = Em.ArrayController.extend({
content: [],
myObserver: function () {
//check changed property
//do stuff if changed to some specific value
}.observes('[email protected]')
});
So far so good - the observer fires when the property of any model changes. However, when it fires, I have no idea which model had changed - i have to iterate over models and compare that property with old values stored elsewhere to figure it out, which is very clumsy and inefficient. I tried to check the arguments
that the observer receives, but they are also of no use: console.log(arguments)
from within observer gives the following: [Class, "[email protected]"]
, and console.log(arguments[0].toString())
gives <App.ListController:ember366>
- the controller itself and the property string.
So my question is: is there a way to know which model has changed when observing the array's @each
property?
When observer fires, I want to check whether the watched property has changed to some specific value, and if so, do some stuff.
As suggested I will check the itemController
now.
You can achieve this in current ember using reduceComputed or arrayComputed.
It would be good to know your use case though: very likely there is a better approach than manually creating an observer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With