在 bootstrap 弹出窗口中,如何从函数的结果中获取内容
in bootstrap popovers, how to obtain content from the results of a function
也许我不习惯使用函数,但我无法将 bootstrap 弹出窗口转换为 return 从函数派生的字符串。有人可以帮忙吗?
$(".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
}
});
}
});
}
});
我放弃了使用 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];
}
});
也许我不习惯使用函数,但我无法将 bootstrap 弹出窗口转换为 return 从函数派生的字符串。有人可以帮忙吗?
$(".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
}
});
}
});
}
});
我放弃了使用 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];
}
});