extjs panel中动态增加items

(mvc模式下的实现)

{
							xtype : 'panel',
							height : 140,
							width : 500,
							id : 'dynamicFC',
							hidden : true,
							margin : '0px 0px 4px 0px',
							layout : {
								columns : 2,
								type : 'table',
								align : 'center'
							},
							items : [

							]
						}
function中

OnChange : function(field, newValue, oldValue, eOpts) {
		
		// get fields container
		fc = Ext.getCmp('dynamicFC');
		fc.removeAll();//把panel中原有的移除,不然会累加-------1
		Ext.Ajax.request({
			url : '',//从数据库中请求数据,动态获取items中的数据
			params : {
				Id : newValue
			},
			method : 'Get',
			success : function(response, opts) {

				var success = Ext.decode(response.responseText).success;
				// 获取后台数据成功时
				if (success) {
					var displayFieldsArray = Ext.decode(response.responseText).obj;
					for (i = 0; i < displayFieldsArray.length; i++) {
						displayFields = displayFieldsArray[i];
						displayFieldLabel = displayFields.displayFieldLabel;
						fieldName = displayFields.fieldName;
						displayFieldType = displayFields.displayFieldType;
						displayFieldValue = displayFields.displayFieldValue;
						// 动态添加items
						var items = {
							xtype : displayFieldType,
							name : fieldName,
							fieldLabel : displayFieldLabel
						}
						fc.add(items);//把获取的items添加到panel中,注意和----1中的顺序,先移除再添加,才不会导致累加
						fc.doLayout();
					}
				} else {

				}
			},
			failure : function(form, action) {
				Ext.Msg.alert('信息提示', action.result.message);
			}
		});
	},


  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值