还有一个类似的问题.
假设以下路线:
App.Router.map(function (match) {
match('/').to('index');
match('/posts').to('posts', function (match) {
match('/').to('postsIndex');
match('/:post_id').to('post', function (match) {
match('/comments').to('comments', function (match) {
match('/').to('commentsIndex');
match('/:comment_id').to('showComment');
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
是否可以访问post_id和comment_id进入ShowCommentRoute?否则我应该忘记模型中的复合键?
为什么CommentsRoute#model(params)和CommentsIndexRoute论点总是空的?如何在Post何时检索评论?
我的小提琴.
也运行此示例(有控制台日志显示问题.
经过一番调查后更新:
只会PostRoute有params.post_id.只会ShowCommentRoute有params.comment_id和不会有params.post_id.
对于模型具有复合键的应用程序,这是不可接受的.如果我们showComment一步一步过渡,我们可以获得Comment实例:
App.ShowCommentRoute = Ember.Route.extend({
model: function(params) {
var post_id = this.controllerFor('post').get('content.id');
return App.Comment.find(post_id, params.comment_id);
}
});
Run Code Online (Sandbox Code Playgroud)
但如果我们直接访问,这将无效/posts/1/comments/1.this.controllerFor('post')总是在这种情况下undefined.
*IndexRoute(PostRoute以及PostInderRoute在这个例子中)Mik*_*tti 13
使用ember-1.0.0-rc.1,现在可以在直接访问url时访问父路由的模型.
App.ShowCommentRoute = Ember.Route.extend({
model: function(params) {
var post = this.modelFor('post');
return App.Comment.find(post.get('id'), params.comment_id);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1112 次 |
| 最近记录: |