What is the best way to use ajax loading for model with dynamic segments router v2



I’m facing the problem with dynamic segments router v2. here is the link for js http://jsfiddle.net/q9zvU/5/.

The model method of route isn’t calling with linkTo and transitionTo. (It is clearly stated in ember’s doc). But for my case, I really need to have a point to load the data from ajax request in route.

Thanks, Linn


I have not found a solution yet that enables loading the model methond in the Route object. Is it possible to load the data from your ajax request in a controller or view before transitionTo(‘campaigns’)?


But the problem is in the serialize method. I can’t interpret into route if the obj is null or empty.


It is hard to answer without knowing your intention. In general, there are two entry points to access a route: (1) through URL, (2) through method call transitionTo( ‘route’, models )

Although transitionTo allows you to pass model, you may want to provide solution for direct URL access as well.


Actually, my requirement is to load the data from ajax whenever route is called because I really can’t provide the data into transitionTo or to the route, the data is paginated and depends on the return of ajax request.

The problem is the object is set into controller’s model before setupController hook is called. So can’t use ArrayController in this case.


if your requirement is to load data whenever the route is entered, you can use “enter” method as below:

App.CampaignsRoute = Ember.Route.extend({

enter: function() {

// do your initialization here ...

// you can even defer your ajax loading till controller is set up, and let controller deals with it
var controller = this.controllerFor('campaigns');
controller.set('some_params', 'value');

} });


Please have a look at Upcoming Async Router API which provides an API to make all of this much easier to do.