正确的使用JQuery-Mobile / Phonegap的方法?
问题描述:
什么是正确的方式(到今天)一起使用JQuery Mobile和Phonegap?
What is the correct way (to this date) to use JQuery Mobile and Phonegap together?
两个框架都需要加载才能使用。
Both frameworks need to load before they can be used. How can I be sure that both are loaded before I can use them?
答
可以使用JQuery的延迟功能。
You can use deferred feature of JQuery.
var deviceReadyDeferred = $.Deferred();
var jqmReadyDeferred = $.Deferred();
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
deviceReadyDeferred.resolve();
}
$(document).one("mobileinit", function () {
jqmReadyDeferred.resolve();
});
$.when(deviceReadyDeferred, jqmReadyDeferred).then(doWhenBothFrameworksLoaded);
function doWhenBothFrameworksLoaded() {
// TBD
}