问题
I have a list of categories that are loaded on the application route:
ApplicationRoute = Em.Route.extend({
model: function() {
return Em.RSVP.hash({
collections: this.store.find('collection'),
categories: this.store.find('category'),
links: this.store.find('link')
});
}
});
This triggers the categories index action on the server, as expected. I am doing this because I need to load a list of categories for a menu.
I also have a category route:
Router.map(function() {
this.route('category', { path: '/categories/:category_id' });
});
CategoryRoute = Em.Route.extend({
model: function(params) {
this.store.find('category', params.category_id);
}
});
Since there's already a list of categories in the store, there's no request to the server. However, here I want to show more detailed information. I want to send a request to the server's show action.
I am probably not thinking in "the ember way", but it seems to me that I either have to, somehow, force the server request in the route, or create a separate model for the menu categories.
How should one go about this, with ember-data?
Notes: ember.js-1.1.2 and ember-data-1.0.0.beta.3
回答1:
I ended up using a separate CategoriesList model. Still, this feels suboptimal.
来源:https://stackoverflow.com/questions/19680014/ember-data-loading-data-for-a-menu-best-approach