Ember bound block helper

I'm wondering if the registerBoundHelper in ember was ever meant to be able to handle the block style helpers. For example, I created the following:

Ember.Handlebars.registerBoundHelper('unlessUndefined', (context, options) ->
  unless typeof context == "undefined"
    return options.fn(this)
  else
    return options.inverse(this)
)   

The idea being to use it as such:

{{#unlessUndefined choice}}
  {{#if choice}}
    <p>You chose yes</p>
  {{else}}
    <p>You chose no</p>
  {{/if}}
{{else}}
  <p>Make a choice</p>
{{/unlessUndefined}}

The option.fn(this) parts of things don't appear to render any output. When doing this I get an error in the console that says: "You can't use appendChild outside of the rendering process"

If this isn't possible, perhaps somebody can suggest another way to achieve a conditional block that will only show if the bound value isn't undefined?


I just spent a bunch of time fighting this and found a fix of sorts. I looked at the pull request with the implementation of the registerBoundHelper method.

I added the following above this line: https://github.com/emberjs/ember.js/pull/1274/files#L0R357

Ember.run.scheduleOnce('render', view, 'rerender')

It looks like the boundHelper method just wraps the original helper method and creates an anonymous view. The only problem is that the observer puts the anonymous view into render mode without putting the original view into the same first.

At least that's what I think is going on. Anyway, it works for me now. Maybe this is a bug?

链接地址: http://www.djcxy.com/p/68414.html

上一篇: Python subprocess.call阻塞

下一篇: Ember绑定块助手