问题
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.
回答1:
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
回答2:
just use var uie = require('IndicatorWindow');
Also make sure it uses exports inside the JS
来源:https://stackoverflow.com/questions/23008218/requiring-external-javascript-file