我在 Titan Mobile 中进行了简单的登录和菜单显示。这是我的登录代码:
登录.js
function Login() {
var loginView = Titanium.UI.createView({
backgroundColor:'#C4FBFF',
layout:'vertical'
});
var txtUsername = Titanium.UI.createTextField({
width:'75%',
hintText:'Username',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
var txtPassword = Titanium.UI.createTextField({
width:'75%',
hintText:'Password',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
passwordMask:true
});
var btnLogin = Titanium.UI.createButton({
title:'Login',
width:'75%'
});
loginView.add(txtUsername);
loginView.add(txtPassword);
loginView.add(btnLogin);
btnLogin.addEventListener('click',function(e){
var alertDialog = Titanium.UI.createAlertDialog({
title: 'Confirmation',
message: 'You will be logged in as ' + txtUsername.value + ', continue?',
buttonNames: ['Yes','No']
});
alertDialog.addEventListener('click',function(e){
if (e.index === 0){ //Yes Pressed
var isAndroid = Ti.Platform.osname === 'android' ? true : false;
var MainMenu = isAndroid === true ? require('ui/handheld/android/MainMenu') : require('ui/handheld/MainMenu');
var mainMenuWindow = Titanium.UI.createWindow({
backgroundColor:'#336699',
title:'Main Menu',
modal:true,
navBarHidden: isAndroid === true ? true : false
});
var mainMenu = new MainMenu(mainMenuWindow);
mainMenuWindow.add(mainMenu);
mainMenuWindow.open();
}
else{ // No Pressed
makeAlert('Login','Please contact your system administrator');
}
});
alertDialog.show();
});
function makeAlert(title, message) {
var customAlertDialog = Titanium.UI.createAlertDialog({
title: title,
message: message,
buttonNames: ['Ok']
});
return customAlertDialog.show();
}
return loginView;
}
module.exports = Login;
这是 MainMenu.js
function MainMenu(_parent){
var mainMenuView = Titanium.UI.createView({
backgroundColor:'#C4FBFF',
layout:'vertical'
});
var btnLeftNavBar = Titanium.UI.createButton({
title:'Logout'
});
var txtTest = Titanium.UI.createTextField({
hintText:'iPhone',
width:'75%',
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
_parent.setLeftNavButton(btnLeftNavBar);
mainMenuView.add(txtTest);
btnLeftNavBar.addEventListener('click',function(e){
_parent.close();
});
return mainMenuView;
}
module.exports = MainMenu;
MainMenu.js 仅在 navBar 上显示一个按钮用于关闭窗口..
主要问题是我想将 tabGroup 放在 MainMenu.js 上,这样我就可以从中选择一些菜单。
是否可以将 tabGroup 放在窗口内?有什么建议,所以我可以在不更改主应用程序结构的情况下将 tabGroup 放在 MainMenu.js 中?
非常感谢..