• Extjs 组件继承 模板说明(同GridPanel案件)



    1. 重写initComponent()方法,并在该方法在调用父类的initComponent()方法。  
    如:subclass.superclass.initComponent.call(this);

    2. 在initComponent中,出现以下语句,覆盖父类属性
    Ext.apply(this, {
        title : "aaa"
    });

    3. 基本模板代码例如以下:
    Ext.ns("my.component");
    
    my.component.MyGridPanel = Ext.extend(Ext.GridPanel,{
    	/**
    	 * 初始化组件
    	 */
    	initComponent : function(){
    		// 数据仓库
    		var store = this.store;
    		if(!store){
    			store = this.buildStore(this.baseParams);
    		}
    		// 列模型
    		var cm = this.cm;
    		if(!cm){
    			cm = this.buildCm();
    		}
    		// 复选框.组件属性使用selModel配置
    		var sm = new Ext.grid.CheckboxSelectionMedol();
    
    
    		Ext.apply(this, {
    			// 这里加上组件的属性
    			selModel : sm,
    			// 分页工具条
    			bbar : new Ext.PagingToolbar({
    			
    			}),
    			colModel : new Ext.grid.ColumnModel({
    				// 这里加上列模型的属性
    				columns : cm;
    			}),
    			// 对该组件设置监听器
    			listeners : {
    				"dbclick" : function(){},
    				"rowClick" : function(){},
    				......
    			}
    		});
    		my.component.MyGridPanel.superclass.initComponent.apply(this);
    	},
    	/**
    	 * 构建store
    	 */
    	buildStore : function(baseParams){
    		Ext.apply(baseParams, {
    			// 分页条件
    		});
    		return new Ext.data.JsonStore({
    			url : "",
    			idProperty : "", // id属性值配置
    			totalProperty : "", // 
    			autoLoad : boolean,
    			root : "data" // 数据的根。后面的json格式对象数组。
    			fields : [
    				{name : "", mapping : ""},
    				{name : "", mapping : ""},
    				......
    			]
    		});
    	},
    	/**
    	 * 构建数据列
    	 */
    	buildCm : function(){
    		return [
    			{name : "", dataIndex : ""},
    			{name : "", dataIndex : ""}
    		];
    	},
    	
    	// 通过选择模型,获取选中的记录。是多条的
    	getSelections : function(){
    		var records = this.getSelectionModel().getSelections();
    		return records;
    	}
    
    	// 通过选择模型。获取选中的记录。仅仅有一条
    	getSelected : function() {
    		var record = this.getSelectionModel().getSelected();
    	}
    	
    });


    
    
    
    

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    shop--8.商品类别--辅助工具
    shop--8.商品类别--初始化展示
    数据库的三个基本范式
    DB2 常用命令
    用Java编程计算出所有的"水仙花数"
    用Java编程计算兔子生兔子的问题
    用Java编程计算猴子吃桃问题
    MySQL安装详解图文版(V5.5 For Windows)
    SQL 左外连接,右外连接,全连接,内连接
    mysql desc esc 基本命令总结
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4630836.html
Copyright © 2020-2023  润新知