How to modify the sortProperties value dynamically inside an ember.js ArrayController

早过忘川 提交于 2019-12-23 19:24:01

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!