javascriptember.jsember-1

How to reload current route in Ember.js?


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!


Solution

  • From a controller use transitionToRoute:

    this.transitionToRoute('playlist', newModel);
    

    From a route use transitionTo:

    this.transitionTo('playlist', newModel);
    

    For example, imagine you have an action on your controller

    App.PlaylistController = Ember.ArrayController.extend({
     actions: {
       grabNewModel: function(){
         //get some new model
         this.transitionToRoute('playlist', newModel);
       }
     }
    });