Ember Handlebars not automatically putting model in scope

送分小仙女□ 提交于 2020-01-15 07:04:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!