EmberJS {{#with}}阻止不显示

时间:2012-09-24 18:13:09

标签: ember.js towerjs

控制器看起来像这样

class App.ContactsController extends Tower.Controller
  index: (params) ->
    @set('person', App.HighrisePerson.create())
    @render "index"

视图看起来像这样

App.ContactsEditView = Ember.View.extend
  templateName: 'contacts/edit'
  resourceBinding: 'controller.person'
  init: (args...) ->
    @._super(args...)
    console.log(@.get('resource'))
    console.log('inited')

使用上面的块我在控制台中看到资源被设置为我的Ember.Object的实例

但使用以下视图代码

div class: "row-fluid", ->
  text "{{#with resource}}"
  text "Hello"
  text "{{/with}}"

父视图的相关部分

div class: "row-fluid contact-form", ->
  div class: "row-fluid", ->
    h1 "Want to work with us?"
    p "So...you want to be kohactivated!?!? Please take a few moments to fill out the form below and provide us with some details about your project, company or start-up."
  text "{{view App.ContactsEditView}}"

我看不到hello的渲染输出

如果我在#with块之外移动你好,我看到你好,

因此我认为由于某种原因它无法识别资源

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

这是正确的 - 它在当前车把上下文中寻找resource而不是视图(从ember.js 0.9.8开始,我相信它不再是默认上下文)。您需要view.resource代替。

(旁注:相反,要从视图中引用手柄上下文,请使用context.whatever