jQuery Mobile的列表视图 - 检查初始化完成 [英] Jquery mobile listview - check initialization is complete
问题描述
我有codeD我的方式陷入了困境。
我需要调用列表视图(刷新)
名单上,但它可能尚未在我打电话的刷新方法点初始化。
有没有一种方法,以检查是否该组件已初始化或没有?
这是我的错误:
不能调用列表视图的方法之前的初始化
块引用>解决方案在
列表视图
部件被初始化,它给了UI的列表视图
类,所以我们可以测试这个类,看它是否已被初始化://选择列表视图
变量$ myUL = $('#我-UL-元素');//列表项添加到ListView
$ myUL.append('<李I标记\\'M最新及LT;!/李>');//检查列表视图有UI的列表视图类
如果($ myUL.hasClass('UI的列表视图')){ //这个列表视图已经初始化,所以刷新
$ myUL.listview('刷新');
}其他{ //这个列表视图尚未初始化,所以它被初始化
$ myUL.listview(); //或者你可以使用.trigger('创建');
}这应该有助于缓解你得到的错误。
此外,
.hasClass('[类]')
函数返回真正
/假
如果该元素具有[类]
: HTTP ://api.jquery.com/hasClassI've coded my way into a corner.
I need to call
listview("refresh")
on a list, however it may not have been initialized at the point I am calling the refresh method.Is there a way to check if the component has initialized or not?
This is the error I get:
cannot call methods on listview prior to initialization
解决方案When a
listview
widget is initialized, it's given theui-listview
class, so we can test for this class to see if it has been initialized://select the listview var $myUL = $('#my-ul-element'); //add a list-item to the listview $myUL.append('<li>I\'m New!</li>'); //check if the listview has the ui-listview class if ($myUL.hasClass('ui-listview')) { //this listview has already been initialized, so refresh it $myUL.listview('refresh'); } else { //this listview has not yet been initialized, so it gets initialized $myUL.listview();//or you can use .trigger('create'); }
This should help alleviate the error you're getting.
Also, the
.hasClass('[class]')
function returnstrue
/false
if the element has the[class]
: http://api.jquery.com/hasClass这篇关于jQuery Mobile的列表视图 - 检查初始化完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!