【问题标题】:Reuse Meteor template - Isolating events重用 Meteor 模板 - 隔离事件
【发布时间】:2014-06-24 03:29:36
【问题描述】:

我试过了:

  Template.skillsSearch = $.extend Template.skillsSearch,
    rendered: ->
      Session.set('s' + @_id, null)
      Session.set('searchFocused' + @_id, null)

@_id 以前工作过,我想是因为它在 each 语句中。现在我没有这个循环,@{}(对象中没有_id)。

假设我有这个:

body
  +myTemplate
  +myTemplate

如何为每个模板实例获得一个唯一的 id?或者,如何在重用模板时创建唯一的会话密钥?

【问题讨论】:

  • 这是一个常见问题,在流星 0.8.2 中会变得容易一些。我正在写一篇博客文章,描述解决此问题的技术。完成后我会回来查看。
  • 这是我在Scoped Reactivity 上的博文。希望这会有所帮助。

标签: coffeescript meteor pug


【解决方案1】:

我就是这样解决的:

template(name='father1')
  with 'father1'
    +reusedTemplate

template(name='father2')
  with 'father2'
    +reusedTemplate

template(name='reusedTemplate')
  h1 #{aVariable}

然后在咖啡脚本中:

Template.reusedTemplate = $.extend Template.reusedTemplate,
  rendered: ->
    # Here @data contains whatever you pass in with
    # i.e. 'father1' and 'father2' respectively

  aVariable: ->
    # Here @ contains whatever you pass in with
    # i.e. 'father1' and 'father2' respectively

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2013-08-23
    • 2017-11-08
    • 1970-01-01
    相关资源
    最近更新 更多