JQM(jQueryMobile)的问题,AJAX的内容列表视图(“刷新”)不工作 [英] JQM (jQueryMobile) problem with AJAX content listview('refresh') not working
问题描述
这是我在做什么一个模拟的:
函数loadPage(PN){
$('#'+ PN).live('pagecreate',功能(事件,UI){
$('#'+ PN +' - 提交)。点击(函数(){
$ .mobile.changePage({
网址:'?page.php PARM =价值
类型:'后',
数据:$('#形式'+ PN +'_表)
},'滑',假的,假的);
loadAjaxPages(PN);
});
});
功能loadAjaxPages(页){
//这个返回我想要的网页,所有的工作
$阿贾克斯({
网址:'?page.php PARM =价值
键入:POST,
错误:函数(){document.title时='错误'; },
成功:功能(数据){
$('#显示_'+网页+'_页)HTML(数据)。 //删除。第(),导致页面过渡,但如果我使用。第()我可以看到预期的列表视图
}
});
}
在AJAX调用返回,如果我加入。第()(它曾在过去,但我有它的翻页功能方面,改变我如何加载网页,以节省加载时间逻辑),使网页过渡到下一个页面,但我可以看到ListView控件的样式我想要的方式:
$('#显示_'+网页+'_页)HTML(数据)。第()。
删除。第()修复了转换误差,但现在该页面没有风格。我曾尝试列表视图('刷新')
甚至列表视图(刷新,真正的)
,但没有运气。
我如何能得到ListView的任何想法来刷新?
解决方法:
$。阿贾克斯({
网址:'?page.php PARM =价值
键入:POST,
错误:函数(){document.title时='错误'; },
成功:功能(数据){
$('#显示_'+网页+'_页)HTML(数据)。
$(#DIV名UL)列表视图(); //添加DIV包装瓦特/名属性使用刷新
}
});
- 一定要叫
.listview
ul元素上 - 如果它没有早期的风格,你只需要调用
.listview()
,僵尸的刷新功能。如果你的萤火虫设置是正确的,你应该已经看到了一个错误信息,告诉你这一点。
我没有时间静下心来,创造一些code您发布的修复过,但这里有一个小建议,从我:
如果(数据!== NULL){$('#显示_'+网页+'_页)。HTML(数据).find(UL)。列表视图()}
这是不是一个新的全球选择一个位更好。此外 - 你不需要股利,如果你有多个上行线路可以提供详细的选择
注意:上面的code要求数据== NULL
!如果它是空 - 这将抛出一个错误。
This is a mock of what I'm doing:
function loadPage(pn) {
$('#'+pn).live('pagecreate',function(event, ui){
$('#'+pn+'-submit').click( function() {
$.mobile.changePage({
url: 'page.php?parm=value',
type: 'post',
data: $('form#'+pn+'_form')
},'slide',false,false);
loadAjaxPages(pn);
});
});
function loadAjaxPages(page) {
// this returns the page I want, all is working
$.ajax({
url: 'page.php?parm=value',
type: 'POST',
error : function (){ document.title='error'; },
success: function (data) {
$('#display_'+page+'_page').html(data); // removed .page(), causing page to transition, but if I use .page() I can see the desired listview
}
});
}
in the ajax call return if I add the .page() (which worked in the past but I had it out side of the page function, changing the logic on how I load pages to save on loading times), make the page transition to the next page but I can see the listview is styled the way I want:
$('#display_'+page+'_page').html(data).page();
Removing .page() fixes the transition error but now the page does not style. I have tried listview('refresh')
and even listview('refresh',true)
but no luck.
Any thoughts on how I can get the listview to refresh?
Solution:
$.ajax({
url: 'page.php?parm=value',
type: 'POST',
error : function (){ document.title='error'; },
success: function (data) {
$('#display_'+page+'_page').html(data);
$("div#name ul").listview(); // add div wrapper w/ name attr to use the refresh
}
});
- Be sure to call
.listview
on the ul element - If it didn't style earlier, you just call
.listview()
, bot the refresh function. If your firebug setup is correct, you should have seen an error message telling you that.
I didn't have time to get down to creating some code before you posted your fix, but here's a little recommendation from me:
if(data !== null){ $('#display_'+page+'_page').html(data).find("ul").listview() }
This is a bit nicer than a new global selector. Also - you don't need the div and you can provide a detailed selector if you have multiple ULs.
caution: the above code requires data !== null
. If it's null - it will throw an error.
这篇关于JQM(jQueryMobile)的问题,AJAX的内容列表视图(“刷新”)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!