我正在用Titanium构建一个iOS应用程序。第一个窗口是登录页面。当用户输入他们的用户名和密码时,这些值被发送到PHP文件进行身份验证。
如果用户通过了身份验证,即他们有一个唯一的用户名/密码组合,我希望关闭当前窗口并打开新窗口。
这些值将被发送到PHP文件,并且用户正在接受身份验证;但是,当关闭当前窗口的代码运行时(Titanium.UI.currentWindow.close
),将抛出一个错误,指示打开新窗口的文件不存在。但是,引用新窗口的文件确实存在。
我已经将似乎导致错误的代码移到了许多地方,但结果是相同的。
var loginReq = Titanium.Network.createHTTPClient();
loginReq.onload = function()
{
var json = this.responseText;
var response = JSON.parse(json);
if (response.logged == true)
{
alert("Welcome " + response.name + ". Your email is: " + response.email);
username.value = '';
password.value = '';
//This creates the new window after user authentication.
var menuPage = Titanium.UI.createWindow({
title: "Menu",
tabBarHidden: false,
url: 'menuPage.js'
});
//This is supposed to close the current window.
Titanium.UI.currentWindow.close();
//This is supposed to open the new window.
menuPage.open();
}
else
{
alert(response.message);
}
};
发布于 2015-07-20 10:19:19
您应该先打开新窗口,然后从新窗口关闭旧窗口,而不是先关闭窗口,然后再打开新窗口。
menuPage.open({closeWindow: function(){
curWin.close(); }
});
然后,在menuPage.js
中,观察open
事件,一旦触发,就调用您传递给menuPage.js
的函数。
不过,我还是建议您深入研究一下合金。这种方法是非常过时的。
在合金中,你可以这样做:
Alloy.createController('menuPage', {closeWindow: function(){
$.getView().close();
});
在menupage中:
$.getView().addEventListener('open',args.closeWindow());
发布于 2015-07-20 05:40:24
嗨,试着用这个打开一个窗口
var menuPage = require('menuPage');
win = new menuPage({title:''});
谢谢
发布于 2015-07-27 05:00:38
如果您使用的是合金:
文件windowlogin.xml
<Alloy>
<Window id="window_login">
<TextField id="txt_username"></TextField>
<TextField id="txt_password"></TextField>
<Button title="Login" id="btn_login"></Button>
</Window>
</Alloy>
文件windowlogin.js
$.btn_login.addEventListener("click", function(e){
var loginUrl = "http://domain.com/login";
var dataLogin = {
username: $.txt_username.value,
password: $.txt_password.value
};
var loginReq = Titanium.Network.createHTTPClient();
loginReq.onload = function()
{
var json = this.responseText;
var response = JSON.parse(json);
if (response.logged == true)
{
alert("Welcome " + response.name + ". Your email is: " + response.email);
username.value = '';
password.value = '';
//This creates the new window after user authentication.
var menuPage = Titanium.UI.createWindow({
title: "Menu",
tabBarHidden: false,
url: 'menuPage.js'
});
//This is supposed to open the new window.
menuPage.open();
//This is supposed to close the current window.
$.window_login.close();
}
else
{
alert(response.message);
}
};
loginReq.open("POST", loginUrl);
loginReq.send(dataLogin);
});
https://stackoverflow.com/questions/31497891
复制相似问题