简体   繁体   English

如何等待show回调(qtip2)中的ajax函数完成?

[英]How to wait till an ajax function is finished in show callback (qtip2)?

I am using qtip2 for tolltips: 我正在使用qtip2作为收费提示:

function setupTolltip() {
    $("g path").each(function () {
        var path = $(this);
        var sessionId = $("#rsr").attr("data-session");
        var clientId = $("#rsr").attr("data-client");
        $(this).qtip(
            {
                content: {
                    text: function () {
                        var allPlaces = $(this).attr("data-all");
                        var freePlaces = $(this).attr("data-free");
                        var price = $(this).attr("data-price");
                        var tooltipText = "<div>All: " + allPlaces + "<br/>Free: " + freePlaces + "<br/> Price: " + price + "</div>";
                        return tooltipText;
                    }
                },
                events: {
                    show: function () {
                        var levelId = path.attr("level");
                        updateLevelInfo(path, levelId, sessionId, clientId);

                    }
                },
                position: {
                    target: 'mouse',
                    adjust: {
                        x: 10
                    }
                },
                style: {
                    classes: 'ui-tooltip-tipsy ui-tooltip-shadow',
                    tip: true
                }
            });
    });
}

When tooltip shows I make call updateLevelInfo function. 当工具提示显示时,我将调用updateLevelInfo函数。 This function make ajax request and updating attribute which uses qtip . 该函数使用qtip进行ajax请求和更新属性。 The problem in that this is ajax request( I can't use $.get ) and tooltip shows before function finish executed. 问题在于这是ajax请求(我不能使用$.get ),并且在功能完成执行之前显示工具提示。

Why don't you use the AJAX Object used in this official demo ? 您为什么不使用此官方演示中使用的AJAX对象

You should always show a "loading" Information or Image, so there is no problem if your tooltip is shown before loading your content. 您应该始终显示“正在加载”的信息或图像,因此,在加载内容之前显示工具提示没有问题。 (Again see Ajax Demo ) (再次参见Ajax演示

if you want to use show functionality then please use show: function(event, api) (see this example ). 如果要使用show功能,请使用show: function(event, api) (请参见本示例 )。 Then use the var api and give it into your function: 然后使用var api并将其提供给您的函数:

updateLevelInfo(path, levelId, sessionId, clientId, api);

Then you are able to manipulate the tooltip after doing your staff in your function! 这样,在您完成工作后,您便可以操作工具提示!

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

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