【问题标题】:Ember JS - view insertion eventEmber JS - 查看插入事件
【发布时间】:2013-03-03 06:24:28
【问题描述】:

我有以下 Handlebars 模板,其中包含一些在 #each 中输出的视图。

<script type="text/x-handlebars" data-template-name="thread">
  {{#view My.ContainerView}}
      {{#each message in messages}}
          {{view My.MessageView contentBinding="message"}}
      {{/each}}
  {{/view}}
</script>

我正在使用 didInsertElement 事件来捕捉父视图的插入。

我知道在插入每个 My.MessageView 时会触发 didInsertElement,但我想知道的是,当插入 all 的 My.MessageViews 时是否触发了事件?意味着#each 已完成。完全渲染的视图可能存在类似的事件?

// Ember Noobie

【问题讨论】:

    标签: ember.js handlebars.js


    【解决方案1】:

    我遇到了类似的情况,关于在子​​视图呈现后在哪里触发 jquery 事件。在这个论坛的帮助下,我得到了这样的结果:

    下面的视图为我 ajax 中的每个项目呈现一次(对于引导手风琴)。

    App.AccItemView = Em.View.extend
      classNames: ['accordion-group']
      templateName: 'acc_item'
      didInsertElement: ->
        Ember.run.next this, ->
          @.$('.collapse').collapse({parent:"#accordion2"})
    

    还有一个 afterRender 钩子,我仍在自己试验。

    didInsertElement: ->
        Ember.run.scheduleOnce 'afterRender', this, () ->
          @.$('.collapse').collapse({ parent:'#accordion2'})
    

    这里有一个小提琴,如果它有用的话。 http://jsfiddle.net/nrionfx/s59fA/16/

    【讨论】:

    • 事件按以下顺序发生:1)。父视图:didInsertElement 2)。子视图:didInsertElement。 3)。父视图:afterRender。 4)。子视图:afterRender。我想我期望的是 3) 和 4) 会被交换。因此,当所有子视图都完全呈现时,您就会有一个事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多