在自举弹出窗口中,如何从函数结果中获取内容

时间:2018-11-28 20:13:49

标签: function bootstrap-popover

也许我不习惯使用函数,但是我在获取引导程序弹出窗口以返回从函数派生的字符串时遇到麻烦。有人可以帮忙吗?

$(".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 :(得分:0)

我放弃了使用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];
        }
    });