我有一个登录视图,当登录成功时,我想关闭视图并加载新视图。但是我在关闭视图并加载新视图时遇到了一些麻烦。
这是我的login.js视图
Ext.define('MyApp.view.login.Login',{
extend:'Ext.window.Window',
requires:[
'MyApp.view.login.LoginController'
],
controller:'login',
xtype:'login-dialog',
autoShow:true,
width:360,
iconCls:'fa fa-key fa-lg',
title:'Login',
closeAction:'hide',
closable:false,
draggable:false,
resizable:false,
items: {
xtype:'form',
reference:'form',
bodyPadding:15,
defaultType:'textfield',
defaults:{
anchor:'100%',
labelWidth:60,
allowBlank:false,
minLength:3,
msgTarget:'under'
},
items:[{
fieldLabel:'User',
name:'user',
vtype:'alphanum'
},{
fieldLabel:'Password',
name:'password',
inputType:'password'
}],
dockedItems:[{
xtype:'toolbar',
dock:'bottom',
items:[{
xtype:'tbfill'
},{
xtype:'button',
text:'Cancel',
iconCls:'fa fa-times fa-lg',
listeners:{
click: 'onButtonClickCancel'
}
},{
xtype:'button',
text:'Sign In',
formBind:true,
id: 'submit',
iconCls:'fa fa-sign-in fa-lg',
listeners:{
click:'onButtonClickSubmit'
}
}]
}]
}
});
我的控制器LoginController.js
Ext.define('MyApp.view.login.LoginController',{
extend:'Ext.app.ViewController',
alias:'controller.login',
onButtonClickSubmit: function(button, e, options){
var me = this;
if(me.lookupReference('form').isValid()){
this.doLogin();
}
},
doLogin: function(){
var me = this.lookupReference('form');
var user = me.down('textfield[name = user]').getValue();
var password = me.down('textfield[name = password]').getValue();
console.log('Username: ' + user);
console.log('Password: ' + password);
//var submitButton = Ext.getCmp('submit');
me.getEl().mask('Authenticating.....', 'Loading');
Ext.Ajax.request({
url: "http://localhost:8080/extServlet/LoginController",
method: 'POST',
params: {
user: user,
password: password
},
success: function(response){
me.getEl().unmask();
var dt = Ext.decode(response.responseText);
if (dt.isValid){
//Ext.ComponentQuery.query('window')[1].close();
this.getView().close()
Ext.create('MyApp.view.main.Main');
}
else {
Ext.Msg.alert('Status', 'You are not authorised');
}
}
});
}
});
答案 0 :(得分:0)
我得到了未注意的引用错误,说this.getView()不是 功能
范围问题。在AJAX请求中指定范围:
Ext.Ajax.request({
// ...
scope: this
// ...
});