export default Ember.Object.extend({
myArray: Ember.A([null,null,null]),
someFunction: function () {
console.log('i am triggered');
myArray[1] = 3;
}.on('init'),
hasValue: Ember.observer('myArray.[]', function () {
console.log('i am changed');
})
})
What is the mistake here? The observer function never gets triggered though someFunction is always reached.
Use MutableArray#replace:
this.get('myArray').replace(1, 1, [3]);
This means: starting at index 1, replace 1 element, with a 3. This triggers all the necessary dependencies and observers defined as myArray.[].
I'm surprised that your code does not spit out a ReferenceError, since you are referring to an undeclared variable myArray inside someFunction.
There's a convenience function for this that I can't put my finger on at the moment. Also, be aware that observers may not fire during initialization.
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