我创建了一个登录页面,对于我的项目,我使它工作,但问题是,我无法从登录控制器调用登录表单的引用,可能出现什么问题?请参阅下面的代码:
这是我的Login.Js,它是经典的 - > src - >查看 - >登录 - > Login.js:
Ext.define('DevToolsTraining.view.login.Login', {
extend: 'Ext.window.Window',
xtype: 'loginView',
requires: [
'DevToolsTraining.view.login.LoginController',
'Ext.form.Panel'
],
viewModel:{
type: 'login',
data:{
username: ''
}
},
controller: 'login',
title: 'Enter Username',
frame: true,
width: 320,
bodyPadding: 10,
closable: false,
autoShow: true,
layout: 'form',
items: [
{
xtype: 'login',
reference: 'loginForm', //i'm trying to call this
defaultType: 'textfield',
bind: '{Login}',
items: [{
id:'txtUsername',
allowBlank: false,
fieldLabel: 'Username',
name: 'Username',
emptyText: 'enter username here...',
bind: '{username}'
}],
buttons: [{
text: 'Proceed>>',
formBind: true,
handler: 'onProceedClick'
}]
}
]
});
这是app下的控制器 - >查看 - >登录 - > LoginController.js
Ext.define('DevToolsTraining.view.login.LoginController', {
extend: 'Ext.app.ViewController',
alias: 'controller.login',
onProceedClick: function () {
var form = this.lookupReference('loginForm'); //this returns null it's like it can't see the "loginForm" reference
var username = Ext.getCmp('txtUsername').getValue(); //i got the value of the textbox here but i don't like this coz what if I have more textFields
if (username != '')
{
Ext.Ajax.request({
url: '/api/Users/Post',
method: 'POST',
params: username,
scope: this,
success: function (form, response) {
localStorage.setItem("username", username);
this.getView().destroy();
Ext.create({
xtype: 'app-main'
});
},
failure: function(form, response){
Ext.MessageBox.alert("Test");
}
})
}
else {
Ext.MessageBox.alert("Error", "Please enter username to view contacts");
}
},
/**
* Called when the view is created
*/
init: function () {
}
});