`
目步
  • 浏览: 10723 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Ext4.0 动态修改ComboBox选择项(本地模式)

阅读更多

前几天用到ComboBox的本地模式,要动态修改Store显示在ComboBox上

 

写了一个小例子

 

把输入框的值作为ComboBox的动态值添加

 

先写本地store 和 data数据

 

 

	var storeData = 
	[
		['一','1'],
		['二','2'],
		['三','3'],
		['四','4']
	]
	
	var store = Ext.create('Ext.data.ArrayStore', 
	{
		// store configs
		autoDestroy: true,
		idIndex: 0,
		fields: 
		[
			'addText',
			{name: 'addValue', type: 'string'}
		],
		data : storeData
	});

 

 

然后开始写 主框架

 

	var form = Ext.create('Ext.form.Panel',
	{
		title : 'Form Panel',
		renderTo : 'test',
		frame : true,
		buttonAlign : 'center',
		width : 240,
		height : 260,
		fieldDefaults: {
			msgTarget : 'side',
			labelAlign: 'top',
			labelWidth: 100,
			width : 200
		},
		items :[
			{
				xtype : 'textfield',
				fieldLabel : 'ComboBox\'s Text',
				name : 'ComboText',
				allowBlank : false
			},{
				xtype : 'textfield',
				fieldLabel : 'ComboBox\'s Value',
				name : 'ComboValue',
				allowBlank : false
			},
			this.testCombo = Ext.create('Ext.form.field.ComboBox',
			{
				fieldLabel : 'Dynamic ComboBox',
				store : store,
				queryMode : 'local',
				displayField: "addText",
				valueField: "addValue"
			})
		],
		buttons :
		[
			{
				text : 'Add',
				handler : function(btn){
					if(!form.getForm().isValid())
						return;
					storeData.push(
					[
						form.getForm().findField('ComboText').getValue(),
						form.getForm().findField('ComboValue').getValue()
					]);
					testCombo.store.loadData(storeData);
				}
			},{
				text : 'ComboBox Value',
				handler : function(btn){
					alert(testCombo.getValue());
					
				}
			}
		]
	});
   

显示界面

动态值生成

 


 

  • 大小: 25 KB
  • 大小: 32 KB
  • MyJsp.rar (1.1 KB)
  • 描述: 全部代码 注意路径
  • 下载次数: 40
1
2
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics