简体   繁体   English

Qtip2在fnDrawCallBack上显示两次

[英]Qtip2 show twice on fnDrawCallBack

JavaScript and MVC.Net 4** JavaScript和MVC.Net 4 **

I got my table, with pagination. 我有桌子,有分页。 The qtip get data via Ajax On first load, the qtip show's one time, with the correct data. qtip通过Ajax获取数据首次加载时,qtip会显示一次带有正确数据的数据。 When i change a value (via ajax to BD), and redraw the table, the tooltop show twice , in the back, the old (with old data) ,and in front , new the (with correct data) 当我更改一个值(通过Ajax转换为BD)并重新绘制表格时,工具栏显示两次,在后面显示旧的(带有旧数据),在前面显示新的(带有正确数据)

"fnDrawCallback": function () {  //Al volver a dibujar (pintar) la tabla, tambien reinvoca al script de ToolTip
        $('#divTablaTurnos .tooltip-etiqueta').each(function () {
            var idturno = $(this).attr('id');
            $("#divTablaTurnos .tooltip-etiqueta #" + idturno).qtip({
                content: {
                    overwrite: true,
                    text: function (event, api) {
                        api.set('content.text', "Etiquetas: <ul class=\"tooltip-basic\" type=\"square\"></ul>");
                        $.ajax({
                            type: 'GET',
                            url: '/Turnos/TraerListaEtiquetas',
                            dataType: "json",
                            data: { todas: todas, idturno: idturno }
                        })
                            .done(function (data) {
                                var contenido = "Etiquetas: <ul class=\"tooltip-basic\" type=\"square\">";
                                for (i = 0; i < data.length; i++) {
                                    contenido += "<li>" + data[i].toString() + "</li>";
                                };
                                contenido += "</ul>";
                                api.set('content.text', contenido);
                            });
                        //return "Etiquetas: <ul class=\"tooltip-basic\" type=\"square\"></ul>";
                    }
                },
                show: { effect: function () { $(this).fadeTo(500, 1); } },
                hide: { effect: function () { $(this).slideUp(); } },
                position: { target: 'mouse', adjust: { x: 5, y: 5 }, viewport: $(window) }
            });
            //$("#divTablaTurnos .tooltip-etiqueta #" + idturno).qtip('api').options.content.title.text = "asdf";    
        });
    }

And show this after edit the data: Image with the problem, red font show new and old qtip 并在编辑数据后显示: 带问题的图像,红色字体显示新旧qtip

This may seem like a very bad solution but it may work. 这似乎是一个非常糟糕的解决方案,但它可能会起作用。

What happens if you "timeout" qtip? 如果您“超时” qtip,会发生什么?

Maybe the Call Stack is kinda messy with qtip. 也许调用栈有点与qtip杂乱无章。

I would do this: 我会这样做:

setTimeout(function(){
   $("#divTablaTurnos .tooltip-etiqueta #" + idturno).qtip({
            content: {
                overwrite: true,
                text: function (event, api) {
                    api.set('content.text', "Etiquetas: <ul class=\"tooltip-basic\" type=\"square\"></ul>");
                    $.ajax({
                        type: 'GET',
                        url: '/Turnos/TraerListaEtiquetas',
                        dataType: "json",
                        data: { todas: todas, idturno: idturno }
                    })
                        .done(function (data) {
                            var contenido = "Etiquetas: <ul class=\"tooltip-basic\" type=\"square\">";
                            for (i = 0; i < data.length; i++) {
                                contenido += "<li>" + data[i].toString() + "</li>";
                            };
                            contenido += "</ul>";
                            api.set('content.text', contenido);
                        });
                    //return "Etiquetas: <ul class=\"tooltip-basic\" type=\"square\"></ul>";
                }
            },
            show: { effect: function () { $(this).fadeTo(500, 1); } },
            hide: { effect: function () { $(this).slideUp(); } },
            position: { target: 'mouse', adjust: { x: 5, y: 5 }, viewport: $(window) }
        });
}, 0);

Then maybe is re-stacked in the Javascript Call Stack. 然后,也许将其重新堆叠在Javascript Call Stack中。

Let me know if it works! 让我知道它是否有效!

Hope it helps. 希望能帮助到你。

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

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