в загрузочных всплывающих окнах, как получить контент из результатов функции - PullRequest
0 голосов
/ 28 ноября 2018

Может быть, я не привык использовать функции, но у меня возникают проблемы с получением загрузочных всплывающих окон для возврата строки, полученной из функции.Может кто-нибудь помочь, пожалуйста?

$(".person").popover({
        title: 'Default title value',
        trigger: 'hover',
        html: true,
        content: function(){
            var thisID = $(this).attr('id');

                $.ajax({
                type: 'GET',
                url: "people.xml",
                dataType: "xml",
                success: function(xml) {
                    var xmlID = $(xml).find("id"); 
                    $(xmlID).each(function(id, item) {
                        if ($(item).text() == thisID) { 
                            console.log($(item).parent().find('name').text()); //this is the correct name
                            return $(item).parent().find('name').text(); //but nothing appears in the popover content

                        }
                    });
                }
            });
        }
    });

1 Ответ

0 голосов
/ 29 ноября 2018

Я отказался от идеи использования xml и просто использовал вместо этого массивы:

$(".person").popover({
        title: function(){
            var thisID = $(this).attr('id');console.log(thisID);
            thisID = thisID.replace("num","");console.log(thisID);
            return arrNames[thisID];
        },
        trigger: 'hover',
        html: true,
        content: function(){
            var thisID = $(this).attr('id');
            thisID = thisID.replace("num","");
            return arrTitles[thisID];
        }
    });
...