我在DESKTOP浏览器(Chrome for Linux)上运行此代码:
var deviceReadyDeferred = $.Deferred();
var jqmReadyDeferred = $.Deferred();
document.addEventListener("deviceReady", onDeviceReady, false);
function onDeviceReady() {
deviceReadyDeferred.resolve();
}
$(document).one("mobileinit", function () {
console.log('JQM is ready');
jqmReadyDeferred.resolve();
});
$.when(deviceReadyDeferred, jqmReadyDeferred).then( doWhenBothFrameworksLoaded(), failure() );
function doWhenBothFrameworksLoaded() {
alert('success :deviceReadyDeferred is '+deviceReadyDeferred.state());
console.log('Phonegap and JQM are loaded');
EVERYTHING();
}
并且alert
给出了success :deviceReadyDeferred is pending
...而它甚至不应该开火,是吗?
感谢您的帮助。
答案 0 :(得分:2)
您需要将函数引用作为参数传递给then()
方法,不要在调用then()
时调用回调方法(通过在函数名末尾添加()
)
$.when(deviceReadyDeferred, jqmReadyDeferred).then(doWhenBothFrameworksLoaded, failure);
演示:Fiddle