我在运行应用程序构建测试并运行测试版本后使用extjs 6.2创建应用程序,控制台返回错误:
未捕获错误:[Ext.createByAlias]无法识别的别名:data.validator.presence
我知道这与我的登录页面的模型有关,但我不知道如何解决这个问题。
登录页面:
Ext.define('uber.view.login.Login',{
extend: 'Ext.container.Viewport',
xtype: 'login',
requires: [
'uber.view.login.LoginController',
'uber.view.common.Radio',
'uber.view.main.Main',
'uber.model.User',
],
refernce: 'login',
itemId: 'login',
style: {
'background-color': '#f4f4f4',
},
layout: 'fit',
controller: 'login',
abValue: '',
items: [{
xtype: 'container',
layout: 'center',
items: [{
xtype: 'panel',
cls: 'panel-wrap',
width: 500,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'component',
cls: 'title-component',
html: '<a><h1 style="padding: 15px 30px 0;">UberTutor</h1></a>'
},{
xtype: 'panel',
flex: 1,
layout: 'fit',
items: [{
xtype: 'form',
reference: 'formpanel',
padding: 30,
items: [{
//Login/SignUp title
xtype: 'component',
itemId: 'title',
cls: 'inner-title-component',
html: '<h2>Sign Up</h2>',
},{
xtype: 'component',
html: '<hr>'
},{
xtype: 'pageradio',
},{
xtype: 'container',
layout: {
type: 'vbox',
align: 'stretch'
},
defaults: {
anchor: '100%',
xtype: 'textfield',
submitEmptyText: false
},
items: [{
emptyText: 'Username',
name: 'username',
reference: 'username',
},{
emptyText: 'Email',
name: 'email'
},{
emptyText: 'Password',
name: 'password',
inputType: 'password'
},{
emptyText: 'Confirm Password',
name: 'password2',
inputType: 'password'
}]
},{
xtype: 'toolbar',
items: [{
xtype: 'button',
text: 'Sign Up',
handler: 'loginPageStatus'
},'->',{
xtype: 'component',
html: '<a>Forgot username / password?</a>'
}]
}]
}]
}]
}]
}]
});
登录控制器
Ext.define('uber.view.login.LoginController', {
extend: 'Ext.app.ViewController',
alias: 'controller.login',
setlogin: function () {
var me = this;
var status = me.lookupReference('pageradio');
var radio = status.setValue({
rb : 2
});
},
loginPageStatus: function (){
var me = this;
var status = me.lookupReference('pageradio');
var radio = status.getValue();
if (radio.ab != '1') {
this.login();
} else {
this.signup();
}
},
onLoginFailure: function (form, action) {
var me = this;
this.getView().unmask();
var result = uber.util.Util.decodeJSON(action.response.responseText);
Ext.Msg.alert('Error', result.data, Ext.emptyFn);
},
onLoginSuccess: function (form, action) {
var me = this;
this.getView().unmask();
//if login info is correct
me.lookupReference('formpanel').up('login').destroy();
Ext.create('uber.view.main.Main');
// var mainCard = me.lookupReference('mainCardPanel');
var mainCard = Ext.ComponentQuery.query('#mainCardPanel')[0];
// var cardItem = mainCard.getActiveItem;
// var destory = cardItem.destroy();
var card2 = mainCard.add(Ext.create('uber.view.main.MainPage'));
var mainLayout = mainCard.getLayout();
var card = mainCard.setActiveItem('mainpage');
var result = uber.util.Util.decodeJSON(action.response.responseText);
var userName = result.data.userName;
var userNameText = Ext.ComponentQuery.query('#userNameItemId')[0];
userNameText.setText(userName);
},
login: function () {
var me = this;
var formPanel = this.lookupReference('formpanel');
var model = Ext.create('uber.model.User', formPanel.getValues());
var errors = model.validate();
Ext.getBody().mask('Validating... Please Wait...');
if(model.isValid()){
formPanel.submit({
url: '/uber2/main/login!login.action',
method: 'POST',
clientValidation: true,
scope: me,
success: 'onLoginSuccess' ,
failure: 'onLoginFailure'
});
} else {
var message = "";
Ext.each(errors.items,function(rec){
message +=rec.getMessage()+"<br>";
});
Ext.Msg.alert("Validation failed", message, Ext.emptyFn);
}
},
});
登录验证模型
Ext.define('uber.model.User',{
extend: 'Ext.data.Model',
alias: 'model.user',
fields: [
{ name: 'username', type: 'string' },
{ name: 'password', type: 'string' }
],
validators: {
username: { type: 'presence', message: 'please input valid username' },
password: { type: 'presence', message: 'please input valid password' }
}
})
非常感谢一些帮助