【问题标题】:popover hover on table header Meteor弹出悬停在表头 Meteor 上
【发布时间】:2020-05-12 16:42:52
【问题描述】:

我有以下html

<th  scope="col" class="table-success titlerow featurecol"
     id='headerPop'>
    Some Text Header
    <sup>
        <a href='' class="fas fa-info"></a>
    </sup>
</th>

和 Meteor javascript 文件

Template.nameTemplate.events({ 
'mouseenter #headerPop':async function (event,instance){

      instance.$(event.currentTarget).popover({
        html:true,
        title:'The title',
        content:'Some text here'

      })
}
})

虽然弹出框似乎从未出现,但这里有什么问题? 每次用户将鼠标悬停在表格的标题列上时,我都需要显示弹出消息

【问题讨论】:

    标签: javascript meteor bootstrap-4 hover popover


    【解决方案1】:

    每次用户将鼠标悬停在表格的标题列上时,我都需要显示弹出消息

    这表明,you need an event 触发了弹出框,而不是onRendered 回调(即not intended to control event flow)。

    “悬停”功能可以使用mouseovermouseenter 来实现(您需要找出适合您的需要,但mouseenter 似乎是一个不错的候选人):

    Template.nameTemplate.events({
      'mouseenter th' (event, templateInstance) {
        const title = templateInstance.title.get()
        templateInstance.$(event.currentTarget).popover({ title })
      }
    })
    

    您可以在此处使用选择器,例如 th,但您可以使用类选择器指定更窄的范围。

    【讨论】:

    • 嗨@Jankapunkt,我在上面使用了您的建议代码,并在 id 上使用事件而不是 th 来消除事件效果。我可以从日志中看到它被触发但弹出内容,标题没有出现。 (我删除了 on 渲染功能)。我应该用助手或类似的东西返回标题/内容吗?
    • 我更新了我的答案。如果您有动态标题,那么您可以使用 ReactiveVar(或者 ReactiveDict)并将标题传递给 popover 函数。
    • 标题和内容是静态的,所以重写了上面的事件处理程序(检查我的代码)但它仍然没有出现......
    猜你喜欢
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    相关资源
    最近更新 更多