【发布时间】:2012-05-07 06:32:42
【问题描述】:
在我的开发中,我需要包含第三方 javascripts;像money.js (http://josscrowcroft.github.com/money.js/)
实现它的最佳“干净”/“正确”方法是什么?只需将其包含在 index.html 中即可?
【问题讨论】:
标签: sencha-touch sencha-touch-2
在我的开发中,我需要包含第三方 javascripts;像money.js (http://josscrowcroft.github.com/money.js/)
实现它的最佳“干净”/“正确”方法是什么?只需将其包含在 index.html 中即可?
【问题讨论】:
标签: sencha-touch sencha-touch-2
没有。不要直接在index.html 文件中添加额外的javascript 文件。这不是推荐的方式(虽然它可能有效)。
相反,这样做,
index.html 中包含以下行。 microloader是sencha sdk自带的文件夹,主要包含三个文件,development.js、production.js和testing.js,各有各的用途。<appname> 文件夹中,您需要有一个名为app.json 的文件。它看起来像这样..{ "name": "Sencha", // All javascript files go here ... "js": [ { "path": "../../sencha-touch-all-debug.js" }, { "path": "app.js", "update": "delta" }, { "path": "http://josscrowcroft.github.com/money.js/", "update": "delta" } ], "css": [ { "path": "../../resources/css/sencha-touch.css", "update": "delta" }, { "path": "resources/css/app.css", "update": "delta" } ], ..... ..... ..... }
【讨论】:
index.html。当涉及到使用一些本地附加 js 文件时,上述解决方案对我来说非常适合。
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=true"></script> 以在我们的应用程序中使用 Google 地图。无论如何,不客气:-)
如果您使用 Sencha Cmd,您的 index.html 可能如下所示:
<!-- The line below must be kept intact for Sencha Command to build your application -->
<script id="microloader" type="text/javascript" src=".sencha/app/microloader/development.js"></script>
因此,在更改 app.json 后,您需要刷新您的应用:
sencha app refresh
【讨论】:
纯 javascript 为我解决了问题。我只是在启动函数中包含了这段代码:
var scriptTag = document.createElement('script');
scriptTag.src = 'specify the path here...';
document.body.appendChild(scriptTag);
scriptTag 被附加到索引文件的正文中。
【讨论】:
如果外部 JavaScript 库是本地的,则以下内容适用于 Ext JS 5.0.0。编辑完成后,运行“sencha app build”
对 app.json 中的三个 JSON 元素进行更改。 (1).js (2)CSS (3) 资源
{ "name": "Sencha", // All javascript files go here ... "js": [ { "path": "app.js", "bundle": true }, { "path": "leaflet/leaflet.js", "bundle": true } ], "css": [ { "path": "bootstrap.css", "bootstrap": true }, { "path": "leaflet/leaflet.css", "bootstrap": true } ], ..... /** * Extra resources to be copied along when build */ "resources": [""leaflet/leaflet.js","leaflet/leaflet.css"], ...... ...... }
【讨论】: