简体   繁体   English

引导程序弹出窗口内的Emberjs出口

[英]Emberjs outlet inside a bootstrap popover

I'm using bootstrap popover in my app and I need to render an outlet inside it. 我在我的应用程序中使用bootstrap popover,我需要在其中渲染一个插座。

I have this nested route : 我有这个嵌套的路线:

this.resource('pages', function(){
    this.resource('page', { path: ':id' }, function(){
        this.resource('edit', function(){
            this.resource('images', function(){
                this.resource('image', { path: ':image_id'}, function(){
                    this.route('edit');
                })
            }); 
        }); 
    });
});

When the user is here => /pages/1/edit/ when he click on an image it route to /images but render the {{outlet}} inside the popover like this : 当用户在这里=> /pages/1/edit/时,当他单击图像时,它会路由到/images但会在弹出窗口内部呈现{{outlet}} ,如下所示:

<div class="popover-content hide">
    {{outlet}}
</div>

This is my popover initialisation : 这是我的弹出窗口初始化:

 $img.popover({
       html: true,
       content: function() { 
       return $('.popover-content').html(); //need to have the outlet here
       }
  }); 

So far, it render correctly my outlet, but inside the images template, I have some button that modify the DOM and it doesn't update the html. 到目前为止,它可以正确显示我的出口,但是在图像模板内部,我有一些用于修改DOM的按钮,并且它不会更新html。 Unless if I close and open the popover again I can see the modification. 除非关闭并再次打开弹出窗口,否则看不到修改。

Is it possible to render the outlet directly inside the code ? 是否可以在代码内部直接渲染插座? or is it possible to have my popover being updated ? 还是可以更新我的弹出窗口?

Thanks for the help. 谢谢您的帮助。

Ember and Handlebars don't like this because it's basically copying the html content of a div and plopping it into another. Ember和Handlebars不喜欢这样,因为它基本上是复制div的html内容并将其放入另一个。 But that html alone isn't everything that's needed. 但是,仅html并不是全部所需。 Ember is magic and there's lots of stuff happening in the background. 灰烬是魔法,背景中发生了很多事情。

Your hidden div is real ember stuff, so let's try not to mess with it by calling .html() on it. 您隐藏的div是真正的余烬,所以让我们通过在其上调用.html()来避免混乱。 My idea is to literally move the DOM itself instead. 我的想法是从字面上移动DOM本身。

first, modify your popover function call to always create this placeholder div: 首先,修改您的popover函数调用,以始终创建此占位符div:

content: '<div id="placeholder"></div>',

next, detach the content div from the dom in the didInsertElement of the view: 接下来,在视图的didInsertElement中将内容div与dom分离:

// get the popover content div and remove it from the dom, to be added back later
var content = Ember.$('.popover-content').detach();

// find the element that opens your popover...
var btn = Ember.$('#btn-popup-trigger').get(0);

// ... and whenever the popover is opened by this element being clicked, find the placeholder div and insert the content element
// (this could be improved.  we really just want to know when the popover is opened, not when the button is clicked.)
btn.addEventListener("click", function() {
    content.appendTo("#placeholder");
});

since the content div is immediately detached when didInsertElement is called, you can remove the "hide" css class from the content div. 由于在调用didInsertElement时会立即分离内容div,因此您可以从内容div中删除“隐藏” css类。

edit: i tried this on my own project and it broke two-way binding. 编辑:我在我自己的项目上尝试过,它打破了双向绑定。 the controller updated my handlebars elements, but any two-way bound {{input}} helpers did not update the controller/model. 控制器更新了我的车把元素,但是任何双向绑定的{{input}}助手都没有更新控制器/模型。 i ended up using a single-item dropdown menu, and used this to prevent the menu from closing too quickly: Twitter Bootstrap - Avoid dropdown menu close on click inside 我最终使用了一个单项下拉菜单,并以此来防止菜单关闭过快: Twitter Bootstrap-避免在单击内部时关闭下拉菜单

See these links for an alternative approach to putting Ember stuff in Bootstrap popovers: 有关将Ember内容放入Bootstrap弹出窗口的替代方法,请参见以下链接:

Bootstrap Popovers with ember.js template 使用ember.js模板引导Popovers

https://cowbell-labs.com/2013-10-20-using-twitter-bootstrap-js-widgets-with-ember.html https://cowbell-labs.com/2013-10-20-using-twitter-bootstrap-js-widgets-with-ember.html

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

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