Bootstrap   发布时间:2022-04-18  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了twitter-bootstrap – 更新data-content属性时,Twitter bootstrap js popover内容不会更新大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用弹出窗口显示一些信息,我在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>

然后我的脚本

$(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);
                });
        )};
}

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

解决方法

你是正确的,正确的方法是提供内容:function(){return someDynamicContent},如你所提到的.我看到你可能遇到的唯一问题是你可能没有意识到$(‘.player_name_li’).data(‘content’)不会自动与$(‘​​.player_name_li’)的操作保持同步. (“数据内容”).您需要确保在AJAX回调中更改的那个与您在内容定义中引用的那个相同.

如果你定义

$('.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')}
  })

然后你需要使用

huh.data('content',value.new_tablE);

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

大佬总结

以上是大佬教程为你收集整理的twitter-bootstrap – 更新data-content属性时,Twitter bootstrap js popover内容不会更新全部内容,希望文章能够帮你解决twitter-bootstrap – 更新data-content属性时,Twitter bootstrap js popover内容不会更新所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。