我在下面尝试做的是使用部分来使我的视图更加模块化。不幸的是,这不起作用。
我明白了
Uncaught TypeError: Cannot read property 'view' of undefined in the (compiled) _dataForLeftPane.js @ the following line,
stack1 = foundHelper ? foundHelper.call(depth0, stack1, {hash:{}}) : helperMissing.call(depth0, "outlet", stack1, {hash:{}});
如果我删除了在 container.hjs 中声明的部分(请参见下面的代码)并放置它们各自的内容,那么一切正常。但只有当我引入部分时,事情才会停止工作。
file: app_router.js.coffee
root: Ember.Route.extend(
index: Ember.Route.extend(
route: '/'
connectOutlets: (router) ->
router.get('applicationController').connectOutlet('container')
router.get('containerController').connectOutlet('dataForLeftPane', 'dataForLeftPane', [{login:'wycats'},{login:'tomdale'}])
router.get('containerController').connectOutlet('dataForRightPane', 'dataForRightPane', [{id:'1234'},{id:'qwerty'}])
)
)
file: views/application_view.js.coffee
App.ApplicationView = Ember.View.extend(
templateName: 'application'
)
App.ContainerView = Ember.View.extend(
templateName: 'a/container'
)
App.DataForLeftPaneView = Ember.View.extend(
templateName: 'a/dataForLeftPane'
)
App.DataForRightPaneView = Ember.View.extend(
templateName: 'a/dataForRightPane'
)
file: templates/a/container.hjs
{{> _a_leftPane}}
{{> _a_rightPane}}
file: templates/a/_leftPane.hbs
{{outlet dataForLeftPane}}
file: templates/a/_rightPane.hbs
{{outlet dataForRightPane}}
file: templates/a/dataForRightPane.hjs
{{#each person in controller}}
{{person.id}}
{{/each}}
file: templates/a/dataForLeftPane.hjs
{{#each person in controller}}
{{person.name}}
{{/each}}