需要外部JavaScript文件 [英] Requiring external JavaScript file
问题描述
在阅读了SOcelerator论坛中所有相关的答案以及帖子之后,我仍然无法使它起作用:
After reading all the relevant answers in SO and posts in the Appcelerator forums I still can't get this to work:
我有一个用Appcelerator开发的应用程序,我想加载一个
I have an application developed in Appcelerator, and I want to load an external JavaScript file in some of my controllers.
我的应用程序结构如下:
My App structure is as follows:
+ app
- assets
- controllers
- models
+ lib
- IndicatorWindow.js
...
在控制器内部,我有以下代码:
Inside a controller I have the following code:
var uie = require('lib/IndicatorWindow');
但是当我在Android手机上运行它时,我得到了:
But when I run this on an Android phone I get:
未捕获的错误::找不到请求的模块:lib/IndicatorWindow
Uncaught Error: Requested module not found: lib/IndicatorWindow
我还尝试将lib
文件夹放置在app
之外,并使用其他路径,例如/lib/IndicatorWindow
和app/lib/IndicatorWindow
.
I have also tried placing the lib
folder outside of app
, and using other paths such as /lib/IndicatorWindow
and app/lib/IndicatorWindow
.
我什至尝试使用Ti.include()
来获得相同的结果.但是我宁愿使用require()
,因为我更喜欢使用CommonJS模块.
I even tried using Ti.include()
instead, with the same result. But I would rather use require()
since I prefer using CommonJS modules.
推荐答案
在Assets文件夹中创建一个lib文件夹,然后将js文件粘贴到该文件夹中,就可以像在经典的:)中一样要求文件了
Make a lib folder inside assets folder and paste the js file there and you would be able to require file just like you do in classic :)
谢谢
这篇关于需要外部JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!