如何在Tianium studio android项目中从另一个js文件访问js文件
我是钛工作室的新手,正在使用alloy mvc框架。我在controller文件夹中创建了两个js文件。一个是index.js(在创建项目时自动创建)和home.js。现在我想从index.js打开home.js on button event(比如从EclipseAndroid应用程序中的另一个活动启动新活动)。这是我的密码: index.js:如何在Tianium studio android项目中从另一个js文件访问js文件,android,model-view-controller,titanium,titanium-alloy,Android,Model View Controller,Titanium,Titanium Alloy,我是钛工作室的新手,正在使用alloy mvc框架。我在controller文件夹中创建了两个js文件。一个是index.js(在创建项目时自动创建)和home.js。现在我想从index.js打开home.js on button event(比如从EclipseAndroid应用程序中的另一个活动启动新活动)。这是我的密码: index.js: function login_Click(e){ Ti.include('home.js'); hello(); }
function login_Click(e){
Ti.include('home.js');
hello();
}
$.index.open();
其中,login_click(e)是一个按钮onClick事件
和home.js:
function hello(){
//$.home.open();
alert("Opened");
}
//exports.hello = hello;
但每当我运行它并单击按钮时,它就会给出错误
位置:[25,1]alloy/controllers/home.js
按摩:未捕获参考错误:未定义模块
来源:*module.export=控制器强>
这是我的alloy/controllers/home.js:
function Controller() {
require("alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
arguments[0] ? arguments[0]["__parentSymbol"] : null;
arguments[0] ? arguments[0]["$model"] : null;
var $ = this;
var exports = {};
$.__views.home = Ti.UI.createWindow({
backgroundColor: "white",
id: "home"
});
$.__views.home && $.addTopLevelView($.__views.home);
$.__views.label = Ti.UI.createLabel({
text: "Hell Yeah",
id: "label"
});
$.__views.home.add($.__views.label);
exports.destroy = function() {};
_.extend($, $.__views);
$.home.open();
_.extend($, exports);
}
var Alloy = require("alloy"), Backbone = Alloy.Backbone, _ = Alloy._;
module.exports = Controller;
请帮帮我。我尝试了require()方法。我尝试使用$.home.open()直接打开;但什么都没用。我该怎么办????Thanx提前…您必须使用Alloy来执行此操作,要打开主控制器视图,只需执行以下操作:
function login_Click(e){
var homeController = Alloy.createController('home');
// If home.xml's container is a Window this will work
homeController.getView().open();
}
或者,如果您试图调用不同文件中其他js文件的方法,则需要导出该函数才能使用它。 例如: home.js index.js 就这样
exports.myFunction = function(){
alert("I am in");
}
var home = require("home");
home.myFunction();