If I have a model of products and in my view I loop over them both of the below is valid.
Which one should I use? Is there a reason for both?
I prefer controller.model
, seems more explicit.
{{#each product in controller.model}}
<div>{{product.artist}}</div>
{{/each}}
{{#each product in controller.content}}
<div>{{product.artist}}</div>
{{/each}}
Which one should I use?
Actually neither. Instead you should bind to the controller itself, like this:
{{#each product in controller}}
<div>{{product.artist}}</div>
{{/each}}
While controller.content
and controller.model
appear to work at first, you'll find that this approach breaks for more advanced use cases like sorting and specifying an itemController.
Is there a reason for both?
AFAIK there is no difference between using controller.content
and controller.model
. The model property is really an alias to the content property.
// Ember controller definition:
model: Em.computed.alias('content')
From ember source code seems that the model
is an alias for content
:
Ember.ControllerMixin = Ember.Mixin.create({
...
model: Ember.computed.alias('content'),
...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.