关于Ember.js指南中的{{linkTo}} [英] about {{linkTo}} in Ember.js Guide
问题描述
我正在阅读 Ember.js模板指南。在上述链接的第一个例子的句柄部分,他们使用
I'm reading guide of Ember.js templates. In the handlebar part of the first example of above link, they used
{{#linkTo posts.post post}}
但我以为
{{#linkTo posts.post}}
将工作。
为什么需要第二个参数'post'?
我阅读说明:
如果路由具有动态段,则表示
段的模型。默认情况下,Ember.js将替换对象的id属性值
的段。
If the route has a dynamic segment, a model that represents the segment. By default, Ember.js will replace the segment with the value of the object's id property.
但是我可以'将此解释与上述问题联系起来。
but I can't associate this explanation with question above.
推荐答案
#linkTo
帮助需要三个参数。
- 在您的情况下,路由
posts.post
- 上下文,这里是您在循环中引用的特定
post
对象 - 支持选项哈希(目前
标题
)
- The route, in your case
posts.post
- The context, here it is the particular
post
object you are referring to in the loop - An options hash (currently
title
is supported)
因为 posts.post
route是一个动态路由,例如它可以是一个帖子的集合之一,我们必须提供您想要链接到的特定帖子的 #linkTo
帮助器。
Because the posts.post
route is a dynamic route, e.g. it can be for one of a collection of posts, we must provide the #linkTo
helper with which particular post you are wanting to link to.
这篇关于关于Ember.js指南中的{{linkTo}}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!