需要外部 JavaScript 文件 [英] Requiring external JavaScript file

查看:16
本文介绍了需要外部 JavaScript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了 SO 中的所有相关答案以及 Appcelerator 论坛中的帖子后,我仍然无法使其正常工作:

After reading all the relevant answers in SO and posts in the Appcelerator forums I still can't get this to work:

我有一个在 Appcelerator 中开发的应用程序,我想加载一个 我的一些控制器中的外部 JavaScript 文件.

I have an application developed in Appcelerator, and I want to load an external JavaScript file in some of my controllers.

我的App结构如下:

+ 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/IndicatorWindowapp/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆