我有一个在应用程序路由上加载的类别列表:
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')
});
}
});
这将触发服务器上的类别索引操作,如预期的那样。我这样做是因为我需要为菜单加载类别列表。
我还有一个类别路线:
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 操作发送请求。
我可能没有以"余烬方式"思考,但在我看来,我要么必须以某种方式强制路由中的服务器请求,要么为菜单类别创建一个单独的模型。
应该如何利用余烬数据来做到这一点?
注释:余烬.js-1.1.2 和Ember-data-1.0.0.beta.3
我最终使用了一个单独的CategoriesList模型。不过,这感觉不是最佳的。