[英]How to close modal window from other JS file on titanium mobile?
我在钛合金手机中创建了这个简单的登录应用程序。这是我的代码:
Login.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 MainMenu = require('ui/common/MainMenu');
var mainMenuWindow = Titanium.UI.createWindow({
backgroundColor:'#336699',
title:'Main Menu',
modal:true
});
var mainMenu = new MainMenu();
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(){
var mainMenuView = Titanium.UI.createView({
backgroundColor:'#C4FBFF',
layout:'vertical'
});
var btnClose = Titanium.UI.createButton({
title:'Close',
height:30,
width:150
});
mainMenuView.add(btnClose);
btnClose.addEventListener('click',function(e){
//What should i do here?
});
return mainMenuView;
}
module.exports = MainMenu;
主要问题是我想在按下关闭按钮时关闭模式窗口。 我已经尝试过Titanium.UI.currentWindow.close()
但是它关闭了我的所有应用程序,并且无法在iOS设备上执行。 有什么建议吗? 非常感谢..
// pass parent window in as parameter
var mainMenu = new MainMenu(mainMenuWindow);
mainMenuWindow.add(mainMenu);
现在使用参数
function MainMenu(_parent /*parent window*/){
// other code ...
btnClose.addEventListener('click',function(e){
_parent.close();
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.