简体   繁体   English

MeteorJS:在弹出窗口中不会触发模板事件

[英]MeteorJS: Template event is not trigger when in popover

I have this code. 我有这个代码。 The problem is button viewcart click is not executed when click. 问题是单击时不执行按钮viewcart单击。 Button viewcart is inside a popover. 按钮viewcart在弹出框内。 Any ideas how to trigger the event of button click viewcart? 任何想法如何触发按钮单击viewcart事件?

header.jade header.jade

template(name="header")
  ul.nav.navbar-nav.navbar-right
    li
      button.btn.btn-info.cart(name="cart", type="button", data-container="body", data-toggle="popover", data-placement="buttom") Cart 
    #popover-content.hide
        +cart

header.coffee header.coffee

Template.header.rendered = ->
  $('.cart').popover
    placement : 'bottom'
    html: true
    title: 'cart'
    content: ->
      $('#popover-content').html()
    return

cart.jade cart.jade

template(name="cart") 
    table
        tr
         td
           button.viewcart  View Cart

cart.coffee cart.coffee

Template['cart'].events
  "click .viewcart": ->
      console.log 'im click!' 
      return

You're are creating a new element with this $('#popover-content').html() , it wont be attached to blaze (don't know if this is the right way to put it). 您正在使用$('#popover-content').html()创建一个新元素,该元素不会附加到火焰中(不知道这是放置它的正确方法)。 I faced the same issue with popovers on google maps. 我在谷歌地图上遇到了同样的问题。 Where is the popover placed in the DOM? 弹出窗口放在DOM中的什么位置?

EDIT: One thing you can do is instead of creating the template that way, just render it somewhere and make it appear whenever you need. 编辑:您可以做的一件事是代替以这种方式创建模板,只需将其渲染到某个地方并使其在需要时显示。 You can see how they do it here https://github.com/yogiben/meteor-autoform-modals/ . 您可以在这里https://github.com/yogiben/meteor-autoform-modals/中查看他们的操作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM