【发布时间】:2014-04-03 01:58:18
【问题描述】:
我正在尝试在 Ember 中构建嵌套路由。目标是让#/posts 页面显示一个帖子列表,每个帖子都有一个链接 (#/posts/summary/:post_id) 来嵌套一个名为 summary 的资源。
摘要资源包含 4 个嵌套路由,我们称它们为 (a, b, c, d),这意味着我们有一个类似 #/posts/summary/:post_id/a 的路由。路由“a”的模板包含 id = post_id 的“post”对象的标签。
如何使后模型可用于“a”路线?
这是我当前状态的代码:
/* router.js */
App.Router.map(function(){
this.resource('posts', function(){
this.resource('summary', {path:'summary/:post_id'}, function(){
this.route('a'); /* path autogen to be #/posts/summary:post_id/a */
this.route('b');
this.route('c');
this.route('d');
});
});
});
/* controllers.js */
App.PostsIndexRoute = Ember.Route.extend({
model: function(){
return this.store.find('post');
}
});
App.SummaryRoute = Ember.Route.extend({
model: function(params){
return this.store.find('post', params.post_id);
},
});
App.SummaryIndexRoute = Ember.Route.extend({
model: function(params){
console.log(params.post_id);
return this.store.find('post', params.post_id);
},
});
AdminApp.SummaryARoute = Ember.Route.extend({
model: function(params){
return this.store.find('post', params.post_id);
},
});
/* 'A' template */
I'm in A route. Here's the {{title}} of the post.
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
谢谢!我没有!我现在就试一试,然后回来报告。
标签: javascript ember.js