gpt4 book ai didi

jquery-mobile - 在 ajax 调用后,columntoggle 模式/列按钮中的 jQuery 移动表不起作用

转载 作者:行者123 更新时间:2023-12-04 19:37:38 26 4
gpt4 key购买 nike

问题是:

js 脚本通过 ajax 调用 PHP 脚本。该脚本构建了一些 html 代码,在 columntoggle 模式下产生了一个 h3 标题和一个表格 block 。结果插入到 my_content div 中,调用 table() 以 jqm 方式绘制表格。

function get_table()
{ $.ajax({
type:'post',dataType:'text',cache:false
,url:'script.php'
,data:({token:tok, sort:srt})
,success:function(data,status,request)
{ $('#my_content').html(data);
if($('#my_table').length) $('#my_table').table();
}
}

<body>
<div id="my_content"></div>
</body>

这里是 PHP 脚本构建内容的概念:

<div class="ui-corner-all custom-corners">

<div class="ui-corner-all custom-corners">
<h3>My Table</h3>
</div>

<div class="ui-body ui-body-a">

<table id="my_table" data-role="table" data-mode="columntoggle" border="0" cellpadding="4" cellspacing="1" class="ui-responsive table-stroke" data-column-btn-theme="a" data-column-btn-text="Columns" data-column-popup-theme="a">

<thead>
<tr>
<th data-priority="" colspan="1"><a href="#" onclick="re_sort('def');">Default</a></th>
<th data-priority="1" colspan="2"><a href="#" onclick="re_sort('fil');">Files</a></th>
...
</tr>
</thead>

<tbody>
<td>$type</td>
<td>$number</td>
<td>$ratio</td>
...
</tbody>

<tfooter>
<td>total</td>
<td>$sum_number</td>
<td>100%</td>
...
</tfooter>

</table>

</div>

</div>

效果很好,即使是表格顶部的列按钮也能让用户选择他想显示或不显示的列。

现在在表格标题中,有链接。他们调用一个 js re_sort 函数来更改排序标准,然后重新显示表格。

function re_sort(new_srt)
{ srt=new_srt;
get_table();
}

这也很好。

我的问题是在使用新的排序标准重新绘制表格后,列按钮不再显示/隐藏表格列。

我尝试使用以下方法清理表对象及其事件:

$('#my_table').empty(); or $('#my_content').empty();

之前

$('#my_content').html(data);

还有一些其他技巧,但我卡住了!

注意:

$('#my_table').trigger('create');

也不行。

看来我必须再调用一些东西来告诉 jqm 我要将表重新处理为一个新表。

更新:我写了一个例子来演示这个问题:http://jsfiddle.net/komet163s/2P8BG/20/

最佳答案

尝试在此处添加此 $("#my_table-popup-popup").remove();:

$('#my_content').html(code);
$("#my_table-popup-popup").remove();
if($('#my_table').length) $('#my_table').table();

我在这个答案中找到了解决方案: JQuery Mobile update table via AJAX and column-toggle stops working

似乎有效:http://jsfiddle.net/2P8BG/26/

关于jquery-mobile - 在 ajax 调用后,columntoggle 模式/列按钮中的 jQuery 移动表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22868926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com