How to reload current route in Ember.js?

honzahommer picture honzahommer · Jan 31, 2014 · Viewed 42.9k times · Source

in Ember.js I have route with model. Could you help me, when I'm on route playlist how to reload this route (or set new data to model) called by callback from another JS function? I've been looking to documentation so long, but no help for me.

App.PlaylistRoute = Ember.Route.extend({
 setupController: function(controller, model) {
  $.getJSON('api/playlist.php?' + Math.random().toString(36), function (data) {
   controller.set('model', data);
  });
 }
});

Thanks a lot!

Answer

Atsuhiro Teshima picture Atsuhiro Teshima · May 12, 2014

It seems the solution in the answer won't work for current route. I had a same issue and tried the solution here and it worked.

http://discuss.emberjs.com/t/refresh-current-view-page-after-language-change/4291/5#post_5

In your route.

actions: {
  sessionChanged: function() {
    this.refresh();
  }
}

and in your controller.

observeSession: function() {
  this.send("sessionChanged");
}.observes("session.isAuthenticated"),