javascript - 在 deviceReady sencha touch cordova 应用程序中加载 app.js

标签 javascript cordova extjs sencha-touch-2

我在使用设备 API 时遇到一个问题,问题是 device.uuid 在文档准备好后可用,而 sencha touch 在文档准备好之前加载 app.js,所以当我在 sencha 代码中使用 device.uuid 时会得到什么它显示为空

尝试通过

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

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

如果我将文档.write放在加载函数sencha应用程序之前完美加载 没有 device.uuid

<body onload="allJs();">

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

我该怎么办

最佳答案

使用此函数可以异步获取脚本

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/

关于javascript - 在 deviceReady sencha touch cordova 应用程序中加载 app.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27776231/

相关文章:

javascript - RxJS 相当于 Async.js mapLimit

javascript - 如何用 Jquery 编写这个 if 条件?

javascript - Cordova Socket io xhr 轮询错误

javascript - up() 和 down() 与 Ext.getCmp()

javascript - IE9 中的 ExtJS 5 网格过滤和排序中断

javascript - Ext-JS 在 Controller 中使用 View 表单数据作为 Ajax 请求参数

javascript - Microsoft.Web.UI.WebControls TreeView 不工作 IE 11

javascript - 在 JavaScript 中反转字符串

android - window.openDatabase() 和 window.sqlitePlugin.openDatabase() 函数之间的区别?

javascript - 使用 AngularJS 访问嵌套 JSON