`
capple84
  • 浏览: 7869 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

ext combobox默认展示store数据

阅读更多
项目中需要用到给combobox赋初始值的问题,该初始值并不确定,想控制为store的第一行数据。
试了一些方法,比如监听combobox中的render事件,但是由于是异步加载,在render的时候,数据并未获得。最后改为监听store的load事件搞定。
代码如下:
/**
 * @note 获取枚举值
 * @params enumType 数据库中枚举值类型 comId 控件comboboxID isNeed 第一行数据是否需要默认展示(1-展示)
 * @time 2012-02-23
 * **/
disn.utils.getEnums=function(enumType,comId,isNeed){
	var myEnums = new Ext.data.JsonStore({
								url:BIZCTX_PATH+"/favtype!listEnumDict.action?enumType="+enumType,
								root: 'listEnumDict',
								autoLoad:true, //
								fields: [
									{name:'value',mapping:'enumValue'},
									{name:'text',mapping:'enumName'}
								],
								listeners: {  
						          load : function(combo) {//监听load事件,为combobox赋初始值,store第一行
						          	if(isNeed && isNeed == "1"){
		//store.each(function(record){});//如果不确定需要默认展示的值,可以先进行store的遍历。				          		Ext.getCmp(comId).setValue(this.data.items[0].data.value);
						          	}
						          }
						      } 
	});
	return myEnums;
};
var layoutPanel1 = ColumnPanelHelper.createLayoutPanel(2); 
    layoutPanel1.push({
            xtype: "combo",
            labelStyle: "width:130px;",
            width: 150,
            hasAll:true,
            codeType:"city",
            fieldLabel: "填报城市",
			store:disn.utils.getEnums('CITY_ID','favIndex.cityId','1'),
			mode:"local",
			displayField:"text", 
            valueField:"value", 
			triggerAction: "all",
            id:"favIndex.cityId",
            name:"favIndex.cityId",
            readOnly:true
		 });
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics