Javascript Ext.getCmp未定义
虽然我查看了其他关于同一个问题的帖子,但它们并没有多大帮助。 下面是我试图获取文本框值的代码,但我反复得到相同的错误。 是否有其他方法可用Javascript Ext.getCmp未定义,javascript,extjs,Javascript,Extjs,虽然我查看了其他关于同一个问题的帖子,但它们并没有多大帮助。 下面是我试图获取文本框值的代码,但我反复得到相同的错误。 是否有其他方法可用 initComponent: function() { this.items = [ { xtype: 'form', padding: '5 5 0 5', border: false, style: 'background-color:
initComponent: function() {
this.items = [
{
xtype: 'form',
padding: '5 5 0 5',
border: false,
style: 'background-color: #fff;',
fieldDefaults: {
anchor: '100%',
labelAlign: 'left',
allowBlank: false,
combineErrors: true,
msgTarget: 'side'
},
items: [
{
xtype: 'textfield',
name : 'id',
fieldLabel: 'id',
hidden:true
},
{
xtype: 'textfield',
name : 'name',
id : 'idname',
fieldLabel: 'Name',
allowBlank:false,
blankText:'Name is required'
},
{
xtype: 'textfield',
name : 'accno',
maxLength: 16,
enforceMaxLength : true,
regex: /^.{16}$/,
regexText:'Only 16 Digits please',
//autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '10'},
fieldLabel: 'AccNo'
},
{
xtype: 'textfield',
name : 'trade',
fieldLabel: 'Trade'
},
{
xtype: 'datefield',
name : 'doi',
fieldLabel: 'Date Of Insurance',
editable: false,
value : new Date()
},
{
xtype: 'datefield',
name : 'dd',
fieldLabel: 'Due Date',
editable:false,
value : new Date()
}
]
}
];
this.dockedItems = [{
xtype: 'toolbar',
dock: 'bottom',
id:'buttons',
ui: 'footer',
items: ['->', {
iconCls: 'icon-save',
itemId: 'save',
text: 'Save',
handler: function (button) {
Ext.Msg.alert('You clicked the button');
var txt = Ext.getCmp('idname').value();
//var tf = button.up('window').down('#idname');
Ext.Msg.alert(txt);
},
action: 'save'
},{
iconCls: 'icon-reset',
text: 'Cancel',
scope: this,
handler: this.close
}]
}];
this.callParent(arguments);
}
})) 我想试试
按你的按钮检查
xtype: 'toolbar',
dock: 'bottom',
id:'buttons',
ui: 'footer',
items: ['->', {
iconCls: 'icon-save',
itemId: 'save',
text: 'Save',
scope:this,
handler: function (button) {
Ext.Msg.alert('You clicked the button');
var txtfield = this.query('#idname');
var txt = txfield.getValue();
Ext.Msg.alert(txt);
},
action: 'save'
}
你能尝试
getValue()
而不是value()
,这能纠正问题吗?@weeksdev尝试过但仍然得到相同的错误“TypeError:Ext.getCmp(…)未定义”尝试了你的解决方案,但我得到了这个错误TypeError:this.query不是函数(我的Ext版本是4.0.0)我想我应该问一下,你在这里面扩展了什么类?嗯…文档中显示了这应该是可行的。只是为了再次检查是否向处理程序添加了适当的作用域?如果您可以在控制台上打印出来,或者放一个断点来查看调用的上下文