Extjs 4.1 中grid复选框Ext.selection.CheckboxModel 加载后 默认选中

//3.消费者对品牌分析,商品列表
				var brandGrid = Ext.create('Ext.grid.Panel',{
						region: 'center',
						columnLines: true,
					    store: brandStore,
						multiSelect: true,
			            selModel: {
			            	selType:'checkboxmodel'
						},
						//selModel: selMod,	
					    columns: [
							Ext.create('Ext.grid.RowNumberer', {
								text: '序号',
								width : 30
							}),
					        { header: '品牌', dataIndex: 'brandName', flex: 1 }
					    ],
						listeners:{
						    added:function( Component ,container, pos, eOpts ){
								
						    }
						}
					}
				);
				
	
				
				
				function type3Load(){
					ids = new Array();
					//var names = new Array();
					var selections = brandGrid.getSelectionModel().getSelection();
					for ( var i = 0; i ', {
				                text: '确定',
				                tooltip: '确定',
								//icon: basePath + 'css/icons/fam/add_16.png',
								iconCls: 'ok',
				                handler: function(){
									if(brandWindowFlag){
										type3Load();	
									}else{
										brandWindow.hide();
									}
				                }
				        },{
				                text: '取消',
				                tooltip: '取消',
				                //iconCls: 'add',
								//icon: basePath + 'css/icons/fam/add_16.png',
								iconCls: 'cancel',
				                handler: function(){
									if(brandWindowFlag){
										type3Load();	
									}else{
										brandWindow.hide();
									}
				                }
				        }]
					}
				);



1.错误的写法:
js异常这样会导致view对象没有实例化
//加载品牌数据集,并给品牌下拉框赋初始值
					brandStore.load({
						params: {
							date: Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH, -1),"Ym"),//默认参数
						},
						callback: function(records, operation, success){
//获取grid的复选框对象
							var selMod = brandGrid.getSelectionModel();
							//默认选中10个品牌
							for (var i = 0; i <10; i++){
								selMod.select(i,true,false);	
							};

							//打开品牌窗体
							brandWindow.show();
												}
					});

2.正确的写法:
先打开窗体,然后操作窗体中grid对象的复选框
//加载品牌数据集,并给品牌下拉框赋初始值
					brandStore.load({
						params: {
							date: Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH, -1),"Ym"),//默认参数
						},
						callback: function(records, operation, success){
							//打开品牌窗体
							brandWindow.show();
							//获取grid的复选框对象
							var selMod = brandGrid.getSelectionModel();
							//默认选中10个品牌
							for (var i = 0; i <10; i++){
								selMod.select(i,true,false);	
							};
						}
					});

你可能感兴趣的:(JavaScript)