如何讓jquerymobile推遲執行mobileinit直到加載DOM?如何讓mobileinit暫停執行,直到json加載爲止
我試圖使用模板& JSON在飛行中創建頁面。我的問題是,JSON花費太長時間來加載和jquerymobile已完成mobileinit事件!
示例代碼:
$(document).bind("mobileinit", function(){
console.log("mobileinit");
// get JSON & set template... should wait until this is done!
getData();
//SWIPE SWIPE
$('div[data-role="page"]').live("swipeleft", function(){
var nextpage = $(this).next('div[data-role="page"]');
// swipe using id of next page if exists
if (nextpage.length > 0) {
$.mobile.changePage(nextpage, 'slide');
}
});
$('div[data-role="page"]').live("swiperight", function(){
var prevpage = $(this).prev('div[data-role="page"]');
// swipe using id of next page if exists
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, 'slide', true);
}
});
console.log("mobileinit done");
});
你能告訴我們'getData()`的代碼嗎? – graphicdivine 2011-12-15 09:19:30