在deviceReady sencha touch cordova app中加载app.js.

时间:2015-01-05 09:04:28

标签: javascript cordova extjs sencha-touch-2

我有一个问题我使用设备API问题是device.uuid可以在文档就绪后可用,并且sencha touch在文档准备好之前加载app.js所以当我使用device.uuid时我得到的sencha代码它显示为null

试图通过

调用此函数
<body onload="allJs();">

<script>
    function allJs(){           
                document.write('<script src="all.js"><\/script>');
            }
</script>

如果我在加载功能sencha app加载之前把文档.write完美地加载 没有device.uuid

<body onload="allJs();">

<script>
    document.write('<script src="all.js"><\/script>');
    function allJs(){           
                //document.write('<script src="all.js"><\/script>');
            }
</script>

我应该怎么做

1 个答案:

答案 0 :(得分:3)

您可以使用此功能异步获取脚本

function lazyload() {
    var scriptTag = document.createElement('script'); 
    scriptTag.src = "//my_example.js"; // set the src attribute
    scriptTag.type = 'text/javascript'; // if you have an HTML5 website you may want to comment this line out
    scriptTag.async = true; // the HTML5 async attribute
    var headTag = document.getElementsByTagName('head')[0];
    headTag.appendChild(scriptTag);
}

并准备好使用phonegap或cordova

document.addEventListener('deviceready', function(){
        lazyload();
}, false);

您可以使用jQuery getScript函数或自己创建它,请参阅源代码中的链接

来源:

https://chris.lu/article/read/506de698268c420f0d000004

http://jeremyhixon.com/snippet/loading-javascript-files-asynchronously/