更新数据内容属性时,Twitter引导程序js popover内容不会更新

Roo*_*ter 8 twitter-bootstrap

我正在使用弹出窗口显示一些信息,我在ajax请求后更新.基本上,我正在更新在悬停时触发弹出窗口的元素的data-content属性.我正在检查dom,数据内容的东西肯定在更新,但是popover的内容保持不变.我一直在尝试我能想到的一切,并开始觉得我错过了一些简单的东西.有人可以帮我吗.她的一些代码:

<ul>
   <li class="player_name_li" rel="popover" data-placement="right"
    data-html="true" data-title="Dude" data-trigger="hover"
    data-content="<div class='custom_content'>Heres some content</div>" 
   data-original-title="" title=""><span class="player_name">Dude</span>
   </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

然后我的脚本

$(document).ready(function(){
$('.player_name_li').popover({
     template: '<div class="popover" style="width:250px;"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'});

setInterval(function(){update_scores();}, 6000);

function update_scores()
{
    $.ajax({
        url: HOST_NAME,
        type: 'POST',
        //async: false,
        data: {player_array: my_data_is_generated_from_page)}
    }).done(function(results){
        var obj = $.parseJSON(results);     
        //this reloads the stupid popover data
        $.each(obj.fancy_return, function(index, value){
        $('.player_info_link').each(function(){             
            var huh = $(this).closest('li');
            huh.attr('data-content', value.new_table);
                });
        )};
}
Run Code Online (Sandbox Code Playgroud)

现在就像我说的那样全部像我期望的那样工作,并更新每个popover li的数据内容,我通过检查dom验证了,但是当我将鼠标悬停在li上时,它仍然显示数据内容的旧内容.我已经浏览了一些帖子并尝试在我的popover实例中按功能设置内容,content: function(){return $(this).data('content');}但是这样做不起作用.我也试过破坏并重新创建每个可以正常工作的元素,但由于它在一个区间函数中并自动触发,如果你打开一个让它看起来像马车的话,它会关闭一个打开的弹出窗口.有任何想法吗?

mer*_*erv 8

你是正确的content: function(){return someDynamicContent},正如你所提到的,正确的做法就是给予.我看到你可能遇到的唯一问题是你可能没有意识到$('.player_name_li').data('content')它不会自动与操作保持同步$('.player_name_li').attr('data-content').您需要确保在AJAX回调中更改的那个与您在定义中引用的那个相同content.

如果你定义

$('.player_name_li')
  .popover({
    template: '<div class="popover" style="width:250px;"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>',
    content: function (){return $(this).data('content')}
  })
Run Code Online (Sandbox Code Playgroud)

然后你需要使用

huh.data('content', value.new_table);
Run Code Online (Sandbox Code Playgroud)

如果你这样做,插件将在幕后重新初始化.