简体   繁体   English

Bootstrap Popover不显示popover内容

[英]Bootstrap Popover not displaying popover-content

I am using emberjs with twitter-bootstrap, but only the css so no javascript taken from bootstrap. 我正在使用带有twitter-bootstrap的emberjs,但仅使用CSS,因此没有从引导程序中获取JavaScript。

I want to make the popover work, it pops up, but the popover-content is not displayed, even though it is set. 我要使弹出窗口起作用,它会弹出,但是即使设置了popover-content也不会显示。 Here is my code: 这是我的代码:

popoverTemplate.hbs : popoverTemplate.hbs

<div class="popover fade right in" style="top: 12.5px; left: 242px; height:200px;width:200px; display: block;">
<div class="arrow"></div>
<h3 class="popover-title">A Title</h3>
<div class="popover-content">And here's some amazing content. It's very engaging. right?</div>

My view: 我的观点:

 App.PopoverView = Ember.View.extend({
     templateName: 'popoverTemplate'
 });

Here is the controller issuing the toggle behavior: 这是发出切换行为的控制器:

    showPopover: null,
    init:function(){
        this.set('showPopover',false);
    },
    togglePopoverView: function(){
        this.set('showPopover',!this.get('showPopover'));
    }

And here is my main template, where I set the logic for the popover: 这是我的主模板,在其中设置弹出框的逻辑:

     {{#if showPopover}}
                {{view App.PopoverView}}
     {{/if}}

UPDATE I figured it out, unfortunately you couldn't find the bug in my code - at least what I've put here. 更新我想通了,很遗憾,您找不到我的代码中的错误-至少是我在此处输入的错误。 The problem was that in my template at the beginning I've set the context with the #with helper and forgot about it. 问题在于,在一开始的模板中,我已经使用#with帮助器设置了上下文, #with忘记了它。 So most probably I will delete this question. 因此,很可能我将删除此问题。 Thank you though for the contributions. 谢谢您的贡献。

Register your popover when Ember insert your popover into DOM. 当Ember将弹出窗口插入DOM时,注册弹出窗口。 This is what I do in my project. 这就是我在项目中所做的。 Not exactly, but I hope this can give you a clue to make that work. 不完全是,但是我希望这可以为您提供一个线索,使该工作。

App.PopoverView = Ember.View.extend({
    templateName: 'popoverTemplate',
    didInsertElement: function() {
       this.$('.popover').popover(
            {
                title: $(this).attr('data-title'),
                content: $('#popover-content').html() });
            });
    }
});

Your HTML should look like this: 您的HTML应该如下所示:

<a class="popover" data-title="Title Here">Toggle Popover</a>
<div id="popover-content">
   <!-- content... -->
</div>

Should work without extra code, with popover toggle when you click the link. 应该无需额外的代码即可工作,单击链接时可以使用弹出菜单切换。

There doesn't seems to be any problem with your implementation. 您的实现似乎没有任何问题。

Here is a working bin with your implementation 这是一个工作与实现

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

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