JQuery popover 保留旧变量

JQuery popover keeps old variable

I have a dropdown list that when selected sets a bunch of variables in C#.这些变量然后用于填充弹出窗口,然后用户单击 DDL 旁边的锚点。这工作正常,但事实上,当我更改 DDL 中的值时,弹出窗口会保留旧数据。它永远不会 updates/refreshes 使用新数据。

总而言之,用户单击下拉列表来更改变量。 DDL 旁边有一个帮助图标,用户单击它可以显示弹出窗口,其中包含从 DDL 设置的变量中检索到的数据。

我假设它保留了从页面加载时首次使用时开始的对象数据。我试过多次销毁它、隐藏它并重写它,它只是保留了旧数据。

问题:如何让弹窗接受新数据。

$( document ).ready( function (){
$( "#ShowMeterInfo" ).popover( {
        title: '<h3 class="custom-title"><span class="glyphicon glyphicon-info-sign"></span>  Meter: <%=this.HiddenMeterName.Value%></h3>',
            content: "<p><ul><li><strong>Location:</strong><%=this.MeterLocation %></li><li><strong>Id:</strong> 321654</li><li><strong>Building:</strong><%=this.MeterBuilding%></li><li><strong>Site:</strong><%=this.MeterSite%></li></ul></p>",
            template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div><div class="popover-footer"><a href="#" class="btn btn-info btn-sm">Close</a></div></div>',
            html: true,
    animation: true
    } );

$( document ).on( "click", ".popover-footer .btn", function (){
        $( this ).parents( ".popover" ).popover( 'destroy' );
    } );                                               

});

除了数据不会刷新外,效果很好!

这是因为您使用的元素如下:<%=this.MeterLocation %> 会在 time.of 呈现时将该字段的值放入您的视图中。您需要改为获取对呈现的输入元素的引用并检索值。

因此,在显示弹出窗口时,请使用如下内容:

$('#MeterLocation').val()

这将获取该元素的当前值。