0

我有App.js

(function() {       
    Window = require('ui/tablet/ApplicationWindow');

    }
    new Window().open();
    })();

从那里ApplicationWindow.js加载。
ApplicationWindow.js

function ApplicationWindow() {
    //load component dependencies
    var FirstView = require('ui/common/FirstView');

    //create component instance
    var self = Ti.UI.createWindow({
        backgroundColor:'#ffffff'
    });
    var win2 = Titanium.UI.createWindow({
    backgroundColor: 'red',
    title: 'Red Window'
    }); 

    //construct UI
    var firstView = new FirstView();
    var nav = Titanium.UI.iPhone.createNavigationGroup({
    window: win2
    });
    win2.add(firstView);
    self.add(nav);
    self.open();
    //self.add(firstView);
    if (Ti.Platform.osname === 'ipad') {
        self.orientationModes = [Ti.UI.LANDSCAPE_LEFT] ;
    };
    return self;
}

//make constructor function the public component interface
module.exports = ApplicationWindow;

我得到一个带有 2 个文本字段和一个按钮登录的FirstView.js视图。该视图有一个标题为红色窗口的导航栏。我想在 loginButton Click 上加载 Home.js。这是 loginButtonClick 代码:

  loginButton.addEventListener ('click', function(e){
          //navigate to Home.js
      }); 

我该怎么做。谁能帮帮我。

4

1 回答 1

2

在当前文件中尝试以下方法

loginButton.addEventListener('click', function(e){
    var win = Ti.UI.createWindow({
        backgroundColor : 'white',
        url             : 'home.js' //Path to your js file
    });
    win.open();
});

主页.js

var myWin = Ti.UI.currentWindow;
//You can add your controls here and do your stuff.
// Note that never try to open myWin in this page since you've already opened this window

也可以试试下面的方法

方法二

//In your current page
loginbutton.addEventListener('click', function(e) {
    var Home = require('/ui/common/Home');
    var homePage = new Home();
    homePage.open();
});

您的 Home.js 文件

function Home() {
    var self = Ti.UI.createWindow({
        layout : 'vertical',
        backgroundColor:'white'
    });
    //Do your stuff here
    //Add other controls here

    return self;
}
module.exports = Home;

这个答案,也和你的问题一样

于 2013-07-25T06:39:18.857 回答