我在下面显示的路由结构如下jsfiddle。下山时会显示这个问题,我点击的帖子链接上的应用程序模板所示时,它抛出的错误:emberjs嵌套的路由返回未定义的对象,但对象已定义
Uncaught Error: assertion failed: Cannot call get with 'id' on an undefined object.
此错误是由“后”资源产生的,当我将其更改为下面的代码,一切运行
this.resource('post', function(){});
但我想它在下面所示的形式,这将引发和错误,未定义的对象:
this.resource('post', {path: 'posts/:post_id/'}, function(){})
这是整个路由器和jsfiddle
EmBlog.Router.map(function() {
this.resource("posts", {path: '/posts'}, function(){
this.route('new');
this.route('edit', {path: '/:post_id/edit'});
this.resource('post', {path: 'posts/:post_id/'}, function(){
this.resource('comments', {path: '/comments'}, function(){
this.route('new');
this.route('edit', {path: ':post_id/comment/:comment_id'});
this.route('comment', {path: ':post_id/comment'});
});
});
});
});
在控制台当我运行EmBlog.Router.router.recognizer.names
Object {post.index: Object, posts.new: Object, posts.edit: Object, comments.new: Object, comments.edit: Object, comments.comment: Object…}
这是车把模板
<script type="text/x-handlebars" data-template-name="application">
<h1>Hello from Application template</h1>
<p>{{#linkTo posts.index}}Posts{{/linkTo}}</p>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="posts">
<h1>Hello from posts template</h1>
<p>{{#linkTo post.index}} MyPost{{/linkTo}}</p>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="post">
<h1> Hello from a single post template</h1>
<p>{{#linkTo comments.index}} comments{{/linkTo}}</p>
{{outlet}}
</script>
感谢您的帮助再次。我欠你的不仅仅是感谢,而且已经接受你的回答。欢呼声 – brg 2013-04-10 10:21:22