问题描述
我正在动态填充<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尚未构建listview.我该怎么办?
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.htmlYou 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 Mobile错误“初始化之前无法在ListView上调用方法"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!