问题
I'm using ember 1.0 pre and have a basic array controller that starts out with a default sort property of 'id'
PersonApp.PersonController = Ember.ArrayController.extend({
content: [],
sortProperties: ['id'],
updateSort: function(column) {
this.set('sortProperties', column);
}
});
I'd like to set this dynamically and have the dom updated for free. But when I do a simple setter (shown above) it doesn't update anything in my view or on the dom.
If I need the ability to update this dynamically how can I go about it?
回答1:
The sortProperties must be an array, so I don't know if in your case, column is one.
Here is a js fiddle showing you dynamically setting it: http://jsfiddle.net/Sly7/jZVJA/22/
回答2:
This answer does not respond to the original question, but I experienced this symptom and had a different root issue.
In my case, I was changing the sortProperties dynamically but this was having no effect on my array of models. The issue turned out to be that I was reading my backing array from a wrapper method, which failed to observe the sortProperties, so even though the sortProperties were updating, my template was not redrawing the underlying array.
Updating my wrapper method to observe sortProperties directly did the trick.
来源:https://stackoverflow.com/questions/12476682/how-to-modify-the-sortproperties-value-dynamically-inside-an-ember-js-arraycontr