您的位置:首页 > Web前端 > JavaScript

extjs combobox分页加载数据不显示

2012-04-18 16:04 543 查看
在加一个事件之前是对的可以加载,但是在添加一个事件之后,不可显示了,以下是错误的代码

/**
* YHC
*/

/**
* 分页的Combobox
*/
PagingMedicalcareCbo=Ext.extend(Ext.form.ComboBox,{
/**
* 构造方法
*/
timedelay_Slow:2000,//1000ms=1s
timedelay_fast:1000,//1000ms=1s
form:null,
t:null,
onceFocus:false,//判断第一次获得焦点
width:180,
myStore:null,
currentCboText:null,//当前CBO文本框中的值
constructor:function(conf){
//宽度赋值
this.width=(conf.width!='undefined')? conf.width : this.width;
this.myStore=new Ext.data.JsonStore({
url:"/his/medical_care!ajaxMedicalcareCbo.action",//url地址
root: 'root',
idProperty: 'linkId',
totalProperty:"totalProperty",
fields:[{name:"linkId"},
{name:"orgCode"},
{name:"orgName"},
{name:"dbName"},
{name:"serverType"}],
listeners :{
beforeload:this.onCboBeforeLoad,
scope:this
}
});

//
PagingMedicalcareCbo.superclass.constructor.call(this,{
id:"searchCbo",
name:'searchCbo',
store:this.myStore,
mode:"remote",
pageSize:5,
triggerAction:"all",
displayField:"orgName",
//valueField:"linkId",
width:this.width,
listWidth:220,
fieldLabel:'医疗单位',
value:'输入可搜索(new)',
listeners :{
select:this.onSelected,
keyup:this.onKeyup,
focus:this.onFocus,
scope:this
}
});

},
//设置参数
onCboBeforeLoad:function(store,options){
if(this.currentCboText!=null&&(typeof this.currentCboText)!='undefined'){
//带机构名称
store.baseParams={'medicalCareVo.orgName':this.currentCboText};
}else{
//没有任何的参数
store.baseParams={};
}

},
//选择之后,对应赋值
onSelected:function(combo,record,index){
var orgName=this.myStore.getAt(index).get('orgName');
//this.value=orgName;
//alert(this.myStore.getAt(index).get('orgName'));
//alert(record.get('orgName'));
this.form.findField('orgCode').setValue(record.get('orgCode'));
this.form.findField('linkId').setValue(record.get('linkId'));
this.form.findField('dbName').setValue(record.get('dbName'));
this.form.findField('serverType').setValue(record.get('serverType'));
},
//键盘弹起的时候 ,赋值当前文本值
onKeyup:function(combo,e){
this.currentCboText=Ext.getCmp('searchCbo').getValue();
//切记 清除(很重要) 下一次需要清除上一次
if(this.t){
window.clearInterval(this.t);//清除延时执行
}
//如果此时用户将文本框的值删除完之后(也就是没有任何的值)
if(this.currentCboText==''){
this.t=window.setInterval('Ext.getCmp("searchCbo").myStoreLoadData()', this.timedelay_fast);
return;
}
//延时执行,避免用户输入太快,导致访问服务器次数增加,节约性能
this.t=window.setInterval('Ext.getCmp("searchCbo").myStoreLoadData()', this.timedelay_Slow);

},
//--myStore重新加载数据
myStoreLoadData:function(){

//重新加载数据
this.myStore.load({
params:{start:0,limit:5}
});
//切记 清除(很重要)
if(this.t!=null){
window.clearInterval(this.t);//清除延时执行
}
},
//--设置Form对象的方法
setForm:function(form){
this.form=form;
},
//--第一次获得焦点的时候
onFocus:function(combo){

if(!this.hasOnceFocus){
this.onceFocus=true;
this.setValue('');//判断是否是第一次
}
}
});


经改正后的代码,事件的名字onFocus更换,还有变量名onceFocus更换就OK 了

命名有冲突:

正确代码:

/**
* YHC
*/

/**
* 分页的Combobox
*/
PagingMedicalcareCbo=Ext.extend(Ext.form.ComboBox,{
/**
* 构造方法
*/
timedelay_Slow:2000,//1000ms=1s
timedelay_fast:1000,//1000ms=1s
form:null,
t:null,
hasOnceFocus:false,//判断第一次获得焦点
width:180,
myStore:null,
currentCboText:null,//当前CBO文本框中的值
constructor:function(conf){
//宽度赋值
this.width=(conf.width!='undefined')? conf.width : this.width;
this.myStore=new Ext.data.JsonStore({
url:"/his/medical_care!ajaxMedicalcareCbo.action",//url地址
root: 'root',
idProperty: 'linkId',
totalProperty:"totalProperty",
fields:[{name:"linkId"},
{name:"orgCode"},
{name:"orgName"},
{name:"dbName"},
{name:"serverType"}],
listeners :{
beforeload:this.onCboBeforeLoad,
scope:this
}
});

//
PagingMedicalcareCbo.superclass.constructor.call(this,{
id:"searchCbo",
name:'searchCbo',
store:this.myStore,
mode:"remote",
pageSize:5,
triggerAction:"all",
displayField:"orgName",
//valueField:"linkId",
width:this.width,
listWidth:220,
fieldLabel:'医疗单位',
value:'输入可搜索(new)',
listeners :{
select:this.onSelected,
keyup:this.onKeyup,
focus:this.onPromptFocus,
scope:this
}
});

},
//设置参数
onCboBeforeLoad:function(store,options){
if(this.currentCboText!=null&&(typeof this.currentCboText)!='undefined'){
//带机构名称
store.baseParams={'medicalCareVo.orgName':this.currentCboText};
}else{
//没有任何的参数
store.baseParams={};
}

},
//选择之后,对应赋值
onSelected:function(combo,record,index){
var orgName=this.myStore.getAt(index).get('orgName');
//this.value=orgName;
//alert(this.myStore.getAt(index).get('orgName'));
//alert(record.get('orgName'));
this.form.findField('orgCode').setValue(record.get('orgCode'));
this.form.findField('linkId').setValue(record.get('linkId'));
this.form.findField('dbName').setValue(record.get('dbName'));
this.form.findField('serverType').setValue(record.get('serverType'));
},
//键盘弹起的时候 ,赋值当前文本值
onKeyup:function(combo,e){
this.currentCboText=Ext.getCmp('searchCbo').getValue();
//切记 清除(很重要) 下一次需要清除上一次
if(this.t){
window.clearInterval(this.t);//清除延时执行
}
//如果此时用户将文本框的值删除完之后(也就是没有任何的值)
if(this.currentCboText==''){
this.t=window.setInterval('Ext.getCmp("searchCbo").myStoreLoadData()', this.timedelay_fast);
return;
}
//延时执行,避免用户输入太快,导致访问服务器次数增加,节约性能
this.t=window.setInterval('Ext.getCmp("searchCbo").myStoreLoadData()', this.timedelay_Slow);

},
//--myStore重新加载数据
myStoreLoadData:function(){

//重新加载数据
this.myStore.load({
params:{start:0,limit:5}
});
//切记 清除(很重要)
if(this.t!=null){
window.clearInterval(this.t);//清除延时执行
}
},
//--设置Form对象的方法
setForm:function(form){
this.form=form;
},
//--第一次获得焦点的时候
onPromptFocus:function(combo){

if(!this.hasOnceFocus){
this.hasOnceFocus=true;
this.setValue('');//判断是否是第一次
}
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: