ember 2.0 嵌套动态模板呈现错误的模板
ember 2.0 nested dynamic templates renders the wrong template
其他人在Whosebug上发布了类似的问题,但还没有答案...
我的第一个动态路由成功了。我在第一个动态路由中有一个嵌套动态路由,但该嵌套路由的模板从未显示。
此路线有效(显示 post.hbs):
#/home/post/29
但是这条路线:
#/home/post/29/comment/123
我希望显示 comment.hbs,但 post.hbs 仍然显示。
我的路由器看起来像:
this.route('home', { path: '/home'}, function() {
this.route('post', {path: "/post/:post_id"}, function() {
this.route('comment', {path: "/comment/:comment_id"}, function() {
....
在我的 post.hbs 我有这个:
<div {{action 'doNavigateToComment' comment}}>
在我的 route\home\post.js 中我有:
doNavigateToComment(comment_id) {
this.transitionTo('home.post.comment', this.get('postId'), comment_id);
}
我的文件结构如下所示:
\routes
home.js
\home
post.js
\post
comment.js
\templates
\home
index.hbs
post.hbs
post\
comment.hbs
在控制台中启用了跟踪,但未显示任何错误。
我正在使用 ember 1.13.5(其行为应类似于 ember 2.0)
您的 post.hbs
中需要 {{outlet}}
才能在 comment.hbs
中呈现。
编辑:
由于您要求将 post
替换为 comment
,您可以使用以下选项之一:
1) 编辑您的路由器,使 comment
不会嵌套到 post
,而是嵌套到 home
:
this.route('home', { path: '/home'}, function() {
this.route('post', {path: "/post/:post_id"}, function() {});
this.route('comment', {path: "/comment/:comment_id"}, function() {});
....
2) 更改您的 post.hbs
以按照您的意愿行事:
{{#if pathIsForPosts}}
...
{{else}}
{{outlet}}
{{/if}}
pathIsForPosts
可能是一个计算的 属性,它分析 path
和 return true
或 false
(如果它是帖子的路径)或评论。
其他人在Whosebug上发布了类似的问题,但还没有答案...
我的第一个动态路由成功了。我在第一个动态路由中有一个嵌套动态路由,但该嵌套路由的模板从未显示。
此路线有效(显示 post.hbs):
#/home/post/29
但是这条路线:
#/home/post/29/comment/123
我希望显示 comment.hbs,但 post.hbs 仍然显示。
我的路由器看起来像:
this.route('home', { path: '/home'}, function() {
this.route('post', {path: "/post/:post_id"}, function() {
this.route('comment', {path: "/comment/:comment_id"}, function() {
....
在我的 post.hbs 我有这个:
<div {{action 'doNavigateToComment' comment}}>
在我的 route\home\post.js 中我有:
doNavigateToComment(comment_id) {
this.transitionTo('home.post.comment', this.get('postId'), comment_id);
}
我的文件结构如下所示:
\routes
home.js
\home
post.js
\post
comment.js
\templates
\home
index.hbs
post.hbs
post\
comment.hbs
在控制台中启用了跟踪,但未显示任何错误。
我正在使用 ember 1.13.5(其行为应类似于 ember 2.0)
您的 post.hbs
中需要 {{outlet}}
才能在 comment.hbs
中呈现。
编辑:
由于您要求将 post
替换为 comment
,您可以使用以下选项之一:
1) 编辑您的路由器,使 comment
不会嵌套到 post
,而是嵌套到 home
:
this.route('home', { path: '/home'}, function() {
this.route('post', {path: "/post/:post_id"}, function() {});
this.route('comment', {path: "/comment/:comment_id"}, function() {});
....
2) 更改您的 post.hbs
以按照您的意愿行事:
{{#if pathIsForPosts}}
...
{{else}}
{{outlet}}
{{/if}}
pathIsForPosts
可能是一个计算的 属性,它分析 path
和 return true
或 false
(如果它是帖子的路径)或评论。