我有一个小问题。
我有index.js
var loc = require('location');
function doClick (){
loc.doIt();
}
在 location.js 中我有这些
var dee = 12;
exports.doIt = function() {
alert(dee);
};
这意味着当我单击按钮时我可以收到警报,但是,我想在不需要单击 onLoad 的情况下获取这些信息 - 此外我想返回两个值而不仅仅是一个值。 我该如何解决这个问题,也许它确实有一个简单的解决方案,但因为我已经工作了一段时间,我的大脑停止了工作:)
问候
最佳答案
您应该将 location.js 移动到 app/lib 内部(作为模块)。例如:
// app/lib/helper.js
exports.callAlert = function(text) {
alert('hello'+ text);
}
然后在 Controller 中调用它,如下所示:
var helper = require("helper"); // call helper without path and .js extension
helper.callAlert('Titanium');
你的问题应该得到解决:)
关于variables - 如何在appcelerator Alloy中访问另一个js文件中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21728033/