Ember view is not updating after re-ordering array used to create child views Ember view is not updating after re-ordering array used to create child views arrays arrays

Ember view is not updating after re-ordering array used to create child views


Does this help? http://jsfiddle.net/rNzcy/

Putting together this simple example, I was a little confused why the view update didn't "just work" when sorting the content array in the ArrayController. It seems there are 2 simple things you can do to trigger the view update. Either:

  • Set the content array to null, sort the original content, and then set the sorted content.

or

  • Clone the content array when sorting it, via Ember.copy()

I guess Ember detects when a completely new Array object is set, and that triggers all the expected binding/view updates. Otherwise, maybe it's doing some sort of caching and if the Array object does not change (i.e. it's sorted in place) then no bindings fire? Just guessing.

UPDATE:See discussion @ https://github.com/emberjs/ember.js/issues/575#issuecomment-4397658 which has an improved workaround using propertyWillChange() and propertyDidChange() (http://jsfiddle.net/rNzcy/4/) -- should be a lot more efficient then cloning a large array.


I met the same issue. And I don't think observe array.@each or array.length is good practice. At last I found this http://jsfiddle.net/rNzcy/4/ i.e. call this.propertyDidChange('foo')