我有一个基本控制器,其用户对象在登录成功后与用户数据绑定。此时,我需要传递用户对象的视图已经实例化。这是我的基本控制器:
Ext.define('App.abstract.app.Controller', {
extend: 'Ext.app.Controller',
user: {} // user object that can be accessed by any controller
});
现在,这是我的 Main.js 控制器,它从我的基本控制器扩展并实现登录功能:
Ext.define('App.controller.Main', {
extend: 'App.abstract.app.Controller',
refs: [{
ref: 'main',
selector: 'app-main'
},
{
ref: 'header',
selector: 'appheader'
}],
init: function (application) {
this.control({
"loginform": {
loguser: this.onLoginUser
},
'app-main #logoutBtn': {
//click: this.onLogoutUser
}
});
},
onLoginUser: function (form, values) {
var me = this;
values.password = App.util.MD5.encode(values.password);
App.util.Ajax.request({
url: '/api/Security/ValidateUser',
jsonData: values,
success: function (response, opts) {
var obj = Ext.decode(response.responseText);
if (obj.success) {
// sets the base controller user object so it can be available in all app
Ext.apply(me.user, obj.data);
me.getMain().layout.setActiveItem(1);
// HERE I WANT TO PASS MY me.user TO MY MAIN.js VIEW
}
}
});
},
}
});
这是我的 Main.js 视图,我需要获取用户对象,我可以在页脚中设置用户名(南面板)。
Ext.define('App.view.Main', {
extend: 'Ext.container.Container',
requires: [
'Ext.layout.container.Card',
'Ext.layout.container.Border',
'Ext.layout.container.Accordion',
'Ext.form.Label',
'App.view.login.LoginForm',
'App.view.Dashboard',
'App.view.MainPanel',
'App.view.Header',
'App.view.menu.Accordion'
],
xtype: 'app-main',
layout: {
type: 'card'
},
items: [{
xtype: 'container',
layout: {
type: 'hbox',
align: 'stretch'
},
defaults: { flex: 1 },
items: [{
xtype: 'component'
}, {
xtype: 'container',
layout: {
type: 'vbox',
align: 'stretch',
},
defaults: { flex: 1 },
items: [{ xtype: 'component' }, { xtype: 'loginform' }, { xtype: 'component' }]
}, {
xtype: 'component'
}]
},
{
xtype: 'panel',
layout: {
type: 'border'
},
items: [
{
xtype: 'mainmenu',
width: 250,
region: 'west'
},
{
xtype: 'appheader',
region: 'north'
},
{
xtype: 'mainpanel',
region: 'center'
},
{
xtype: 'container',
region: 'south',
items:
[
{
xtype: 'toolbar',
margin: '0',
style: 'background-color:#3892D3;',
items: [
{
xtype: 'displayfield',
id: 'username',
fieldLabel: 'User Name',
width: 100,
labelWidth: 70,
style: 'color:#FFFFFF;',
value: '<span style="color:#FFFFFF;font-size:12px">HERE I NEED THE USER NAME</span>'
}
]
}
]
}
]
}
]
});
有任何线索吗?