我有一个包含以下项目的小组:
{
xtype: 'numberfield',
id: 'articleFastSearch',
listeners: {
scope: this,
specialkey: function(field, e) {
if (e.getKey() == Ext.EventObject.ENTER) {
var val = this.rawValue;
// Do stuff with val
}
}
}
},
{
id: 'articleFastSearchBtn',
text: 'Open article',
scope: this,
handler: function(btn) {
console.log(Ext.get("articleFastSearch"));
var val = Ext.get("articleFastSearch").getValue();
console.log(val);
// Do stuff with val
}
}
数字域上的监听器工作正常,但是我无法从按钮处理程序访问numberfield值。我尝试命名数字字段并使用this.articleFastSearch.getValue()
,但它不起作用。我认为范围可能是错误的?
然后我使用了数字字段并尝试通过dom访问它,如上所示。这给出了一个奇怪的结果,返回的构造函数实际上包含HTMLTableElement
而不是数字字段。我在属性中找不到值,所以我很困惑......页面上没有其他具有相同ID的元素。有什么想法吗?
理想情况下,如果可能的话,我宁愿通过this
变量访问该值,但我会满足于任何有效的解决方案!
答案 0 :(得分:1)
Ext.get()返回Ext.Element。你要找的是Ext.getCmp()你还应该考虑使用新的Ext.ComponentQuery,它也可以作为从Ext.container.AbstractContainer继承的所有类中的快捷键上/下。