问题描述
阅读了SO中的所有相关答案和Appcelerator论坛中的帖子后,我仍然无法正常工作:
我有一个在appcelerator中开发的应用程序,我想加载外部JavaScript文件在我的一些控制器中.
我的应用结构如下:
+ app - assets - controllers - models + lib - IndicatorWindow.js ...
在控制器内部我有以下代码:
var uie = require('lib/IndicatorWindow');
但是,当我在Android手机上运行它时,我会得到:
未被发现的错误:未找到请求的模块:lib/inideatorwindow
我还尝试将lib文件夹放在app外部,并使用其他路径,例如/lib/IndicatorWindow和app/lib/IndicatorWindow.
我什至尝试使用Ti.include(),结果相同.但是我宁愿使用require(),因为我更喜欢使用commonjs模块.
推荐答案
在资产文件夹中制作一个lib文件夹并粘贴在那里的JS文件,您将能够像经典中的文件一样需要文件:)
谢谢
其他推荐答案
只需使用var uie = require('indientatorWindow');
还确保它在JS
内使用导出问题描述
After reading all the relevant answers in SO and posts in the Appcelerator forums I still can't get this to work:
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');
But when I run this on an Android phone I get:
Uncaught Error: Requested module not found: 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.
I even tried using Ti.include() instead, with the same result. But I would rather use require() since I prefer using CommonJS modules.
推荐答案
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 :)
Thanks
其他推荐答案
just use var uie = require('IndicatorWindow');
Also make sure it uses exports inside the JS