<OUTDATED> about {{linkTo}} in Ember.js Guide
Solution 1
The #linkTo
helper takes three parameters.
- 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)
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.
Solution 2
What the other people said in terms of the arguments passed to the #link-to helper in Ember is accurate here is the link to the documentation for anyone that is looking for more info.
You have the route name that you are linking to and the second argument is providing the model context.
Here is more info:
http://emberjs.com/api/classes/Ember.Templates.helpers.html#method_link-to
synthresin
Updated on June 24, 2022Comments
-
synthresin almost 2 years
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}}
but I thought
{{#linkTo posts.post}}
would work.
Why do I need second argument 'post'?
I read the explanation:
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.
-
synthresin over 11 yearsthen posts.post in {{#linkTo posts.post post}} isn't related with {{#each post in posts}} but post, posts defined in the router?
-
Bradley Priest over 11 yearsCorrect I think you can also use
posts/post
, but don't quote me on that -
elrick over 8 yearsfixed the link. the location was changed in the new documentation.
-
sova over 7 years"model context" is a good way to say it, as you can wrap multiple dynamic values into one object [and serialize it] so you can have multiple dynamic segments.