jimcode
jimcode

Reputation: 171

Specify controller and model on a view that doesn't have a router

I have a simple app that is using ember-data to load from a RESTful web service and display the data using the route to specify the model.

App.AreasRoute = Ember.Route.extend({
    model: function() {
        return App.Area.find();
    }
});

Then I can render the data in the handlebars template using {{#each content}}

But I want to have a second area of data from a different model displayed on the page as well. I started by creating a View and then rendering the view as part of my application template using {{view App.AnotherView}} which correctly renders the view.

However, this view doesn't have a route and therefore I have nowhere to tell it where to get it's data from. How do I do this?

Upvotes: 0

Views: 55

Answers (1)

ahmacleod
ahmacleod

Reputation: 4310

The best place to load additional content is in the setupController hook of the route.

For example, if you define your route as

App.AreasRoute = Ember.Route.extend({
    model: function() {
        return App.Area.find();
    },
    setupController: function(controller) {
        controller.set('someArea', App.Area.find('area_id'));
    }
});

Then the Area model with id area_id can be accessed by {{someArea}} in your template.

Upvotes: 1

Related Questions