Events Extjs-创建自定义类时,自定义类中的组件不会访问自定义类变量
我已经创建了一个自定义组件,在它的keyup事件上有一个textfield,我需要过滤存储,但是在事件生成时我没有得到任何变量,但是在创建对象时我得到了对象。 以下是代码-:Events Extjs-创建自定义类时,自定义类中的组件不会访问自定义类变量,events,extjs,components,Events,Extjs,Components,我已经创建了一个自定义组件,在它的keyup事件上有一个textfield,我需要过滤存储,但是在事件生成时我没有得到任何变量,但是在创建对象时我得到了对象。 以下是代码-: WildCardWindow = Ext.extend(Ext.Window, { width : 300, height : 265, resizable:true,
WildCardWindow = Ext.extend(Ext.Window, {
width : 300,
height : 265,
resizable:true,
closeAction:'hide',
title:'WildCard Selection Window',
autoScroll:true,
iconCls:'icon-wildcard',
bodyStyle:'background-color:#FFFFFF',
//@cfg{Array} data-The array of fields/items to show in the window
data: null,
store:null,
/**
* @property
* @type String
* The message displayed when mouse over on an uncommitted field
*/
uncommittMsg : '<b>Warning!</b> This field has been newly added in
the form designer. ' + 'It <i>can</i> be used now,
but you should be sure to save the uncommitted
changes ' + 'in the open form designer window.',
defaultIconCls : '',
initComponent : function(){
this.createStore(this.data);
this.items = this.createDataView();
WildCardWindow.superclass.initComponent.call(this);
},
createDataView: function(){
this.dataView = new Ext.DataView({
store: this.store,
autoWidth:true,
tpl: this.createTpl(),
autoHeight:true,
singleSelect : true,
overClass:'icon-view-over',
selectedClass:'icon-view-selected',
itemSelector:'.icon-dataview-item',
style:'cursor:pointer'
});
this.textField = new Ext.form.TextField({
fieldLabel: 'To',
tabTip:'Start typing to filter by field name',
name: 'f_to',
enableKeyEvents :true,
listeners: {
keyup: function () {
this.store.filter('name',this.textField.getValue(),true,false);
//Here I am not getting this.store and this.textField ???
}}
});
return [this.dataView,this.textField]
},
createStore: function(data){
this.store = new Ext.data.JsonStore({
data:data,
autoDestroy:true,
fields:[
{name: 'id'},
{name: 'name'},
{name: 'fieldclass'},
{name: 'type'},
{name: 'options'},
{name: 'isMultiMember',type:'boolean'},
{name: 'isUnCommitted',type:'boolean'}
]
});
return this.store;
},
listeners:{
close: function(){
this.store.filter('name','',true,false);
}
}
})
WildCardWindow=Ext.extend(Ext.Window{
宽度:300,
身高:265,
可调整大小:正确,
closeAction:“隐藏”,
标题:“通配符选择窗口”,
autoScroll:是的,
iconCls:“图标通配符”,
车身风格:“背景色:#FFFFFF”,
//@cfg{Array}数据要在窗口中显示的字段/项的数组
数据:空,
存储:空,
/**
*@财产
*@type字符串
*鼠标悬停在未提交字段上时显示的消息
*/
UncommitMsg:'警告!此字段是新添加的
表单设计器。“+”现在可以使用了,
但是您应该确保保存未提交的
在打开的窗体设计器窗口中更改“+”,
defaultIconCls:“”,
initComponent:function(){
this.createStore(this.data);
this.items=this.createDataView();
WildCardWindow.superclass.initComponent.call(this);
},
createDataView:函数(){
this.dataView=new Ext.dataView({
商店:这个。商店,
自动宽度:正确,
tpl:this.createTpl(),
自动高度:正确,
singleSelect:true,
超类:'icon-view-over',
selectedClass:'icon-view-selected',
itemSelector:“.图标数据视图项”,
样式:“光标:指针”
});
this.textField=新的Ext.form.textField({
fieldLabel:'到',
选项卡提示:“开始键入按字段名筛选”,
名称:“f_to”,
enableKeyEvents:true,
听众:{
keyup:function(){
this.store.filter('name',this.textField.getValue(),true,false);
//这里我没有得到这个.store和这个.textField???
}}
});
返回[this.dataView,this.textField]
},
createStore:函数(数据){
this.store=new Ext.data.JsonStore({
数据:数据,
自动销毁:对,
字段:[
{name:'id'},
{name:'name'},
{name:'fieldclass'},
{name:'type'},
{name:'options'},
{name:'isMultiMember',类型:'boolean'},
{name:'isUnCommitted',类型:'boolean'}
]
});
把这个还给我的商店;
},
听众:{
关闭:函数(){
this.store.filter('name','',true,false);
}
}
})
在textfield的键控中,我没有得到这个.store和这个.textfield??
任何建议或我错在哪里。
请尽快回复,因为调用该函数时您将失去作用域 你可以做两件事: 使用绑定函数复制作用域: 我认为这也有效,是一个更优雅的解决方案:
var me = this;
this.textField = new Ext.form.TextField({
fieldLabel: 'To',
tabTip:'Start typing to filter by field name',
name: 'f_to',
enableKeyEvents :true,
listeners: {
keyup: function () {
me.store.filter('name',this.getValue(),true,false);
}}
});
请使用缩进设置代码格式,使其更具可读性。