ember-data - loading data for a menu - best approach

风格不统一 提交于 2019-12-24 09:25:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!