以下关于#linkTo帮助器的emberjs指南不显示单独的帖子 [英] following emberjs guide for #linkTo helper does not display individual post
问题描述
我有一个 jsfiddle ,路由如下所示,其中与 emberjs指南 完全相同,当我点击在 #linkTo helper 附加到 {{post.title}} 之后,它应该显示单个帖子,但它不会,而是控制台显示此错误: / p>
未捕获错误:断言失败:无法使用未定义对象的id调用get。
此外,当我单击主页上的帖子链接时,它会显示所有标题,但在控制台中也会显示此错误:
未捕获的错误:您所做的某些事情导致在渲染后重新渲染视图,但在插入到DOM之前。
EmBlog.Router.map(function(){
this.resource(posts,function(){
thi s.route('show',{path:'/:post_id'});
});
});
作为 emberjs指南
< script type =text / x-handlebarsdata-template-name =posts / index>
{{#each post in content}}
< p> {{#linkTo'posts.show'post}} {{post.title}} {{/ linkTo}}< / p> ;
{{/ each}}
< / script>
我看着这个 提交,为{{linkTo}} 的字符串文字添加了支持,特别是下面提供的建议: p>
现在,Ember允许您将字符串文字指定为参数。 {{link to post popular}} 将查找当前上下文中的热门属性,并生成一个指向具有该ID的模型的URL。
似乎唯一的问题是你忘记将上下文传递给posts / show模板中的posts.edit帮助器。
< script type =text / x-handlebarsdata-template-name =posts / show>
< h1> Post< / h1>
< p>您的内容。< / p>
< h3> {{title}}< / h3>
< h3> {{body}}< / h3>
< br />
< p> {{#linkTo'posts.index'}}返回{{/ linkTo}}< / p>
< p> {{#linkTo'posts.edit'content}}编辑帖子{{/ linkTo}}< / p>
< / script>
这是一个工作小提琴,BTW我已经清理了一些,有些东西对我来说似乎没用。
http://jsfiddle.net/rxWzu/ 9 /
I have a jsfiddle with a route as shown below, which is exactly thesame as the one in emberjs guides and when I click on the #linkTo helper attached to {{post.title}}, it ought to show me the individual post but it does not and instead the console shows this errors:
Uncaught Error: assertion failed: Cannot call get with 'id' on an undefined object.
Also when I click the posts link on the home page, it displays all the titles but in the console, it also shows this error:
Uncaught Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.
EmBlog.Router.map(function() {
this.resource("posts", function(){
this.route('show', {path: '/:post_id'}) ;
});
});
The template which is thesame as the emberjs guides
<script type="text/x-handlebars" data-template-name="posts/index">
{{#each post in content}}
<p>{{#linkTo 'posts.show' post}} {{post.title}} {{/linkTo}}</p>
{{/each}}
</script>
I looked at this commit that added support for string literals as param for {{linkTo}} and in particular the suggestions below from that commit:
Now, Ember allows you to specify string literals as arguments. {{#linkTo post popular}} would look up the "popular" property on the current context and generate a URL pointing to the model with that ID. While {#linkTo post "popular"}} would treat the string literal "popular" as the model.
It seems like the only issue was you forget to pass the context to the linkTo posts.edit helper in the posts/show template.
<script type="text/x-handlebars" data-template-name="posts/show">
<h1>Post</h1>
<p>Your content here.</p>
<h3> {{title}} </h3>
<h3> {{body}} </h3>
<br/>
<p> {{#linkTo 'posts.index'}} back {{/linkTo}}</p>
<p> {{#linkTo 'posts.edit' content}} Edit the post {{/linkTo}}</p>
</script>
Here is a working fiddle, BTW I've cleaned up a bit, some things seemed useless for me.
这篇关于以下关于#linkTo帮助器的emberjs指南不显示单独的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!