android - 如何从钛工作室android项目中的另一个js文件访问一个js文件

标签 android model-view-controller titanium titanium-alloy

我是 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/

相关文章:

java - Arrays.sort 在不触发垃圾收集的情况下对二维数组进行排序?

android - 播放videoView时仅在layout-land android中制作全屏

java - Spring mvc thymeleaf 。如何将白标签错误页面显示为模式或弹出窗口或 toast

android - 后台应用程序在 Titanium 中不接收来自 pubnub for android 的消息

在调用选择图像的 Intent 之前,android 、刷新图像缩略图或 sd 卡

java - Android 随机线程错误

c++ - 如何在 Qt 项目 View 中为单个单元格设置委托(delegate)?

jquery - 如何使用 jQuery 简化 MVC View ?

javascript - 在哪里添加字符串原型(prototype)

javascript - 在 TableView 钛中更改和保留已更改的元素