0

这是我的列表视图元素:

<ul data-role="listview" data-inset="true" id="acceptedContent" data-theme="c">
</ul>

创建过程这第一次工作正常,列表视图看起来像它应该的并且看起来工作得很好:

$('#acceptedContent').append('<li><a href="#Info' + results.rows.item(i).infoID + '" data-transition="flow">' + results.rows.item(i).Info + '</a></li>');

然后我调用它来清空 div,它可以工作并清除 div:

$('#acceptedContent').empty();

使用 ajax 帖子刷新页面,当我取回数据时,我将其读入数据库,然后重建页面。此列表是唯一丢失格式的页面。然后我调用第一次构建页面时使用的相同函数。

重建部分数据已填充,但我失去了格式

$('#acceptedContent').append('<li><a href="#Info' + results.rows.item(i).infoID + '" data-transition="flow">' + results.rows.item(i).Info + '</a></li>');

任何建议都将不胜感激,因为我一直在尝试解决这个问题。

我已经尝试了以下操作以及执行顺序,但没有任何工作,我在重建部分进行附加调用后将以下列表视图刷新:

$("#acceptedContent").listview('refresh');
$("#acceptedContent ul").listview('refresh');

谢谢你的帮助。

4

2 回答 2

2

好的,这是您的操作方法:

你有一个这样的列表视图:

<ul data-role="listview" data-inset="true" id="acceptedContent" data-theme="c">
</ul>

你有一些数据,你将循环并格式化为<li/>. li您可以将html 收集到一个变量中并仅附加一次,而不是多次附加:

var li = "";
//your loop, $.each, for or for..in
li += '<li><a href="#Info' + results.rows.item(i).infoID + '" data-transition="flow">' + results.rows.item(i).Info + '</a></li>';
//end of loop

所以现在,您已经在一个名为li. 现在你将如何使用它?把它放在<ul/>

$('#acceptedContent').html(li);

这样你可以减少使用emptyand append。只是html()用来擦除和重写。

现在是重要的部分。您必须刷新列表视图。你必须使用listview("refresh"),但不是以你已经完成的方式。你必须等待html()完成它的工作。只有这样,您必须使用refreshapi,如下所示:

$('#acceptedContent').html(li).promise().done(function () {
   //refresh here - $(this) refers to ul here
   $(this).listview("refresh");
});

你那里有一些按钮。以防万一您可以使用该trigger方法刷新它们。所以你的代码看起来像这样:

$('#acceptedContent').html(li).promise().done(function () {
   //refresh here - $(this) refers to ul here
   $(this).listview("refresh");
   //causes a refresh to happen on the elements such as button etc. WHICH lie inside ul
   $(this).trigger("create");
});

注意: 如果您收到此错误

未捕获的错误:无法在初始化之前调用 listview 上的方法;试图调用方法“刷新”。

改变

$(this).listview("refresh");

$(this).listview().listview("refresh");
于 2013-07-25T18:11:58.023 回答
0

试试下面的代码:

$('div[data-role=page]').page('destroy').page();

我这样使用它:

$("someid").ajaxStop(function(){
 $('div[data-role=page]').page('destroy').page();
});

这很好地重建了我的 CSS。

于 2013-07-25T17:59:56.193 回答