问题
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.
回答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.
回答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
回答3:
For me code below works fine:
{{#each model as |book|}}
<h3>{{#link-to 'book' book}}{{book.title}}{{/link-to}}</h3>
{{/each}}
回答4:
Link-to
has format of inline and block
Reference: EmberJS-Template Link To Inline Helper
来源:https://stackoverflow.com/questions/14453976/outdated-about-linkto-in-ember-js-guide