Cordova 2.4.0 or 2.5.0 or 2.6.0 and requirejs

前端 未结 2 1969
予麋鹿
予麋鹿 2021-02-08 18:39

Cordova 2.4.0 and up supports AMD for loading into javascript. I am specifically looking to use Cordova 2.5.0 with the latest version of RequireJS, backbone, jquery, jquery mob

2条回答
  •  死守一世寂寞
    2021-02-08 19:09

    To use the lazy loading, one option is to use the domReady plugin from requireJS (cf. http://requirejs.org/docs/api.html#pageload).

    Once requireJS has confirmed that the DOM was ready, you can then wait for the device to be ready using the regular deviceready listener.

    require(['require/domReady','cordova/cordova-ios-2.5.0'], function (domReady) {
        domReady(function () {
        console.log("The DOM is ready - waiting for the device");
        document.addEventListener("deviceready", startWhenReady, false);
        }
     });
    
    function startWhenReady()
    {
      console.log("dom and device ready : we can start...");
      // your app
    }
    

    Worked for me!

提交回复
热议问题