【问题标题】:webui popover does not closewebui弹出窗口不关闭
【发布时间】:2018-09-11 17:22:26
【问题描述】:

我使用webui popover 我的代码是:

for(var i=0; i<posts.length; i++){

pre_elem_at = document.createElement("a");
                        pre_elem_at.setAttribute("class", "show-pop-async");
                        pre_elem_at.setAttribute("href", "javascript:void(0)");
                        pre_elem_at.setAttribute("style", "font-size: 14px;margin-left: 15px;background-color: white;padding: 5px;cursor: pointer;");
                        pre_elem_at.innerHTML = 'Get Link';
                        pre_elem_at.post_id = posts[i].id;
                        // $(pre_elem_at).webuiPopover();

                        $(pre_elem_at).webuiPopover('destroy').webuiPopover({
                            type:'async',
                            url:'timeline/pullrequest/share_post?share_link=1&cred='+posts[i].id,
                            content:function(data){

                                data = JSON.parse(data);
                                var html ='<div style="margin:0px; width:100%; overflow:hidden;" class="input-group mb-3">';
                                html += '<div class="input-group-prepend">';
                                html += '<button style="border-radius:2px 0 0 2px;" class="btn btn-primary btn-outline-secondary" type="button">Copy</button>';
                                html += '</div>';
                                html += '<input style="color:#333" value="'+data.share_link+'" type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1">';
                                html += '</div>';
                                return html;
                        },
                        width:'397',
                        height:'16',
                        padding:false,
                        margin:false,
                         trigger: 'click',
                        cache:false,
                        multi:false

                    });
}

它工作得很好,但我有一个问题.. 弹出框没有关闭..即使我添加了'closeable:true'并单击了“x”图标..它仍然没有关闭.. 如果我删除 type:async 属性,它将正确关闭弹出框,但我无法在其中加载我的 div。因为它是一个 ajax 调用。

【问题讨论】:

  • .webuiPopover('hide');那么 .webuiPopover('destroy') 这个不行吗?
  • 我应该在哪里添加那行代码 @AnyMoose ? $(pre_elem_at).webuiPopover('hide'); $(pre_elem_at).webuiPopover('destroy');
  • 是的,尝试将 $(pre_elem_at).webuiPopover('destroy') 替换为 $(pre_elem_at).webuiPopover('hide')...
  • 不,它不起作用.. 如果我将“destroy”替换为“hide”,它会生成此错误而不是 TypeError: $(...).webuiPopover(...).webuiPopover is not a function ..
  • 我认为 type:'async', 有问题,因为如果我删除它。弹出框工作得很好,但它会是空白的,因为它没有从指定的 url 获取数据..

标签: jquery arrays popover webui


【解决方案1】:

我在 pre_elem_at.addEventListener 上添加了 webui 弹出框启动

pre_elem_at.addEventListener("click",function(e){
                            var pid = e.target.post_id;
                            $(this).webuiPopover({
                            type:'async',
                            url:'timeline/pullrequest/share_post?share_link=1&cred='+pid,
                            content:function(data){

                                data = JSON.parse(data);
                                var html ='<div style="margin:0px; width:100%; overflow:hidden;" class="input-group mb-3">';
                                html += '<div class="input-group-prepend">';
                                html += '<button style="border-radius:2px 0 0 2px;" class="btn btn-primary btn-outline-secondary" type="button">Copy</button>';
                                html += '</div>';
                                html += '<input style="color:#333" value="'+data.share_link+'" type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1">';
                                html += '</div>';
                                return html;
                        },
                        width:'397',
                        height:'16',
                        padding:false,
                        margin:false,
                         trigger: 'click',
                        cache:false,
                        multi:false
                    });
                    $(this).webuiPopover('show');
                });

并在我的索引文件中添加了一个 webui 销毁器

//更新以排除弹出框

$(document).on('blur','.show-pop-async, .xpopover',function(e){
var xthis = this;
setTimeout(function(){
   elem = document.activeElement; // This is the element that has focus
   str = $(elem).attr('class');
   arr = str.split(" ");
   n = arr.includes("xpopover");
    if(!n){
      $('.show-pop-async').webuiPopover('destroy');
    }

},1);

});

【讨论】:

  • 问题在于我无法点击弹出框内的copy 按钮
猜你喜欢
  • 2012-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多