我是 titanium studio 和 working alloy mvc 框架的新手。我在 Controller 文件夹中有两个 js 文件。一个是index.js(创建项目时自动创建)和home.js。现在我想在 index.js 的按钮事件上打开 home.js(比如从 eclipse android 应用程序中的另一个 Activity 开始一个新 Activity )。这是我的代码:
index.js:
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=controller;
这是我的 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(); 直接打开但没有任何效果。我需要做什么????提前致谢....
最佳答案
您必须使用 Alloy 来执行此操作,打开 Home Controller View 只需执行以下操作:
function login_Click(e){
var homeController = Alloy.createController('home');
// If home.xml's container is a Window this will work
homeController.getView().open();
}
关于android - 如何从钛工作室android项目中的另一个js文件访问一个js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17073876/