jQuery 移动错误“无法在初始化之前调用列表视图上的方法" [英] jQuery mobile error "cannot call methods on listview prior to initialization"
问题描述
我正在动态填充 <ul data-role="listview">
然后调用 location.href="#Results"
列表所在的位置,最后listview('refresh')
.
I'm dynamically filling a <ul data-role="listview">
then calling location.href="#Results"
where the list is, and finally listview('refresh')
.
所有这些都是在来自同一页面的 Ajax 请求的成功回调中完成的.它或多或少地工作,但我收到以下错误:
All that is done in the success callback of an Ajax request from the same page. It works more or less but I'm getting the following error:
Uncaught cannot call methods on listview prior to initialization; attempted to call method 'refresh'
我猜 jQuery mobile 还没有构建列表视图.我能做什么?
I guess jQuery mobile did not construct the listview yet. What could I do?
推荐答案
http://jquerymobile.com/demos/1.1.0/docs/api/events.html您必须挂钩 pageinit 事件.在此之前您不能调用任何 JQM 方法.即:
http://jquerymobile.com/demos/1.1.0/docs/api/events.html You have to hook on the pageinit event. You can't call any JQM methods prior to this. i.e.:
$('#Results').bind('pageinit', function() {
$('#myListview').listview('refresh');
});
这篇关于jQuery 移动错误“无法在初始化之前调用列表视图上的方法"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!