问题
Typically, Ember automatically puts the route's model in scope when rendering a handlebars template:
<h1>{{ title }}</h1>
Renders:
<h1>My Title</h1>
For some reason, it's not doing that for me with a particular route. I'm just getting an empty <h1></h1>
. However, if I manually put it into scope:
<h1>{{ model.title }}</h1>
Then it works as expected. What might be causing this behavior? My route is basic:
MeetingsShowRoute = Ember.Route.extend
model: (params) ->
@store.find('meeting', params.id)
`export default MeetingsShowRoute`
And both the relevant view and controller is empty.
回答1:
Your controller is probably extending the controller class, when it should be extending object controller.
MeetingsShowController = Ember.ObjectController.extend ...
Rule of thumb:
No Model backed controller
FooControler = Ember.Controller.extend
Single Model backed controller
FooControler = Ember.ObjectController.extend
Collection Model backed controller
FooControler = Ember.ArrayController.extend
来源:https://stackoverflow.com/questions/24274960/ember-handlebars-not-automatically-putting-model-in-scope