Variables 如何在appcelerator alloy中访问另一个js文件中的变量

Variables 如何在appcelerator alloy中访问另一个js文件中的变量,variables,appcelerator,onload,titanium-alloy,Variables,Appcelerator,Onload,Titanium Alloy,我有个小问题 我有index.js var loc = require('location'); function doClick (){ loc.doIt(); } 在location.js中,我有这些 var dee = 12; exports.doIt = function() { alert(dee); }; 这意味着,当我点击按钮时,我可以得到警报,但是,我想获得这些信息,而不需要点击-加载-此外,我想返回两个值,而不仅仅是一个。 如何解决这个问题也许真的很简单,但因为我

我有个小问题

我有index.js

var loc = require('location');
function doClick (){
loc.doIt();
}
在location.js中,我有这些

var dee  = 12;
exports.doIt = function() {
    alert(dee);
};
这意味着,当我点击按钮时,我可以得到警报,但是,我想获得这些信息,而不需要点击-加载-此外,我想返回两个值,而不仅仅是一个。 如何解决这个问题也许真的很简单,但因为我已经工作了一段时间,我的大脑停止了工作:)


关于

您应该将location.js移动到app/lib内部(作为模块)。例如:

// app/lib/helper.js
exports.callAlert = function(text) {
   alert('hello'+ text);
}
然后在控制器中调用它,如下所示:

var helper = require("helper"); // call helper without path and .js extension
helper.callAlert('Titanium');
你的问题应该得到解决:)