EXT動態生成fieldset(可適用於動態添加一行等)

Ext.Ajax.request({
			url : contextPath + "/refreshManager/list",
			waitMsg : '數據處理中...',
			success : function(resp, options) {
				var respText = Ext.util.JSON.decode(resp.responseText);
				var map = new Map();
				for(var i=0;i<respText.data.length;i++){
					if(!map.containsKey(respText.data[i].typeName)){
						var arr = new Array();
						arr.push(respText.data[i]);
						map.put(respText.data[i].typeName,arr);
					}else{
						map.get(respText.data[i].typeName).push(respText.data[i]);
					}
				}	
				map.each(function(key,value,index){
						var fieldset = new Ext.form.FieldSet({
								title: key.trim()+'管理器配置',
								id: 'fieldSet_' + index
						});
						for(var j = 0;j< value.length;j++){
							var panel = new Ext.Panel({
								id: 'fieldSet_' + index+'_'+j,
								layout: 'column',
								border: false,
								items : [{
									columnWidth : .3, 
									border : false,
									layout : 'form',
									items : [{
										xtype : 'compositefield',
										id : value[j].threadId+'_1',
										name : value[j].threadId+'_1',
										fieldLabel : '管理器名稱',
										anchor:'90%', 
										items: [
				                            {xtype: 'displayfield', value: value[j].threadName}
				                        ]
									}/*{
										xtype : 'textfield',
										fieldLabel : '管理器名稱',
										id : value[j].threadId+'_1',
										name : value[j].threadId+'_1',
										value : value[j].threadName,
										disabled : true,
										anchor:'90%'
									}*/]
								},{
									columnWidth : .2, 
									border : false,
									layout : 'form',
									items : [{
										xtype : 'compositefield',
										id : value[j].threadId+'_2',
										name : value[j].threadId+'_2',
										fieldLabel : '推薦週期('+convent(value[j].cycleUnit)+')',
										anchor:'90%', 
										items: [
				                            {xtype: 'displayfield', value: value[j].defaultCyleTime}
				                        ]
									}/*{
										xtype : 'textfield',
										fieldLabel : '推薦週期('+convent(value[j].cycleUnit)+')',
										id : value[j].threadId+'_2',
										name : value[j].threadId+'_2',
										value : value[j].defaultCyleTime,
										disabled : true,
										anchor:'90%'
									}*/]
								},{
									columnWidth : .4, 
									border : false,
									layout : 'form',
									items : [{
										xtype : 'numberfield',
										fieldLabel : '當前週期('+convent(value[j].cycleUnit)+')',
										id : value[j].threadId+'_3',
										name : value[j].threadId+'_3',
										minValue : value[j].minValue,
										maxValue : value[j].maxValue,
										value : value[j].cycleTime,
										anchor:'60%'
									}]
								}]
							});
							fieldset.add(panel);
							fieldset.doLayout();
						}
						refreshManagerPanel.add(fieldset);
						refreshManagerPanel.doLayout();
			    });
			},
			failure : function(response, options) {
				extAlert("error", '系統異常。');
			}
	});

MAP.JS  JS模擬java MAP實現

/**
 * 
 */
Array.prototype.remove = function(s) {
	for (var i = 0; i < this.length; i++) {
		if (s == this[i])
			this.splice(i, 1);
	}
}

/**
 * Simple Map
 * 
 * 
 * var m = new Map(); m.put('key','value'); ... var s = "";
 * m.each(function(key,value,index){ s += index+":"+ key+"="+value+"\n"; });
 * alert(s);
 * 
 * @author dewitt
 * @date 2008-05-24
 */
function Map() {
	/** 存放鍵的數組(遍歷用到) */
	this.keys = new Array();
	/** 存放數據 */
	this.data = new Object();

	/**
	 * 放入一個鍵值對
	 * 
	 * @param {String}
	 *            key
	 * @param {Object}
	 *            value
	 */
	this.put = function(key, value) {
		if (this.data[key] == null) {
			this.keys.push(key);
		}
		this.data[key] = value;
	};

	/**
	 * 獲取某鍵對應的值
	 * 
	 * @param {String}
	 *            key
	 * @return {Object} value
	 */
	this.get = function(key) {
		return this.data[key];
	};

	/**
	 * 刪除一個鍵值對
	 * 
	 * @param {String}
	 *            key
	 */
	this.remove = function(key) {
		this.keys.remove(key);
		this.data[key] = null;
	};

	/**
	 * 遍歷Map,執行處理函數
	 * 
	 * @param {Function}
	 *            回調函數 function(key,value,index){..}
	 */
	this.each = function(fn) {
		if (typeof fn != 'function') {
			return;
		}
		var len = this.keys.length;
		for (var i = 0; i < len; i++) {
			var k = this.keys[i];
			fn(k, this.data[k], i);
		}
	};

	/**
	 * 獲取鍵值數組(類似Java的entrySet())
	 * 
	 * @return 鍵值對象{key,value}的數組
	 */
	this.entrys = function() {
		var len = this.keys.length;
		var entrys = new Array(len);
		for (var i = 0; i < len; i++) {
			entrys[i] = {
				key : this.keys[i],
				value : this.data[i]
			};
		}
		return entrys;
	};

	/**
	 * 判斷Map是否爲空
	 */
	this.isEmpty = function() {
		return this.keys.length == 0;
	};
	
	/**
     * 判斷Map是否包含key
     */
    this.containsKey = function(key) {
        for (i = 0; i < this.keys.length; i++) {
			if (this.keys[i] == key) {
				return true;
			}
		}
		return false;
    };
    
	/**
	 * 獲取鍵值對數量
	 */
	this.size = function() {
		return this.keys.length;
	};

	/**
	 * 重寫toString
	 */
	this.toString = function() {
		var s = "{";
		for (var i = 0; i < this.keys.length; i++, s += ',') {
			var k = this.keys[i];
			s += k + "=" + this.data[k];
		}
		s += "}";
		return s;
	};
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章