如何将ember.js部分添加到模板中?

时间:2012-12-26 13:53:41

标签: ember.js handlebars.js

我在下面尝试做的是使用partials来使我的视图更加模块化。不幸的是,这不起作用。

我得到了


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}}

1 个答案:

答案 0 :(得分:0)

您可以在另一个模板中“调用”view helper的视图。

file: templates/parentView.hjs
{{view.someProperty}}
//here is the parent view calling a template
{{view "App.templateView" contentBinding="view.content"}}

这会将指定的App.templateView与内容绑定一起插入到渲染视图的传递内容属性中。您可以将所需的任何内容作为templateViews内容传递。

这很可能是你想要做的,但我不确定我是否正确地阅读了你的问题。

此外,这在语义上接近于使用传递的本地渲染部分轨道。因此,我认为这可能是您正在寻找的解决方案,因为您指的是“部分”。