我有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;
我在FirstView.js
中获得了一个包含2个文本字段和一个按钮登录的视图。该视图有一个标题为红色窗口的导航栏。我想在loginButton上加载Home.js。
这是loginButtonClick代码:
loginButton.addEventListener ('click', function(e){
//navigate to Home.js
});
我怎么能这样做。任何人都可以帮助我。
答案 0 :(得分:2)
在当前文件中尝试以下方法
loginButton.addEventListener('click', function(e){
var win = Ti.UI.createWindow({
backgroundColor : 'white',
url : 'home.js' //Path to your js file
});
win.open();
});
<强> home.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
您还可以尝试以下方法
方法2
//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;
查看this answer,它也与您的问题相同