Requiring external JavaScript file

℡╲_俬逩灬. 提交于 2019-12-11 10:22:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!