余烬数据-加载菜单数据-最佳方法 [英] ember-data - loading data for a menu - best approach

查看:75
本文介绍了余烬数据-加载菜单数据-最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有应用程序路由上加载的类别的列表:

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.

我也有一个类别路线:

Router.map(function() {
    this.route('category', { path: '/categories/:category_id' });
});


CategoryRoute = Em.Route.extend({
    model: function(params) {
        this.store.find('category', params.category_id);
    }
});

由于商店中已经存在类别列表,因此无需向服务器发出请求。但是,我想在这里显示更多详细信息。我想向服务器的show action发送请求。

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?

注释
ember.js-1.1.2和
ember-data-1.0.0.beta.3

Notes: ember.js-1.1.2 and ember-data-1.0.0.beta.3

推荐答案

我最终使用了单独的CategoriesList模型。尽管如此,这仍然感觉不是很理想。

I ended up using a separate CategoriesList model. Still, this feels suboptimal.

这篇关于余烬数据-加载菜单数据-最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆