我在下面顯示的路由結構如下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