日期:2014-05-16  浏览次数:20314 次

extJS checkboxselectionmodel 默认选中

var itmsDictWfxwStore = new Ext.data.Store({
         proxy: new Ext.data.HttpProxy({
             url:bocoitms_contextPath + "/dict/getAllUsedWfxw.action"
         }),
         reader: new Ext.data.JsonReader({
             root: 'data',
             id:'wfxw',
     fields:["wfxw", "wfxwMs", "wfxwlb", "wfxwlbMs"]
         }),
         remoteSort: false
     });

//加载完成所有数据后默认选中违法行为
      itmsDictWfxwStore.on('load',function(){
              var tempArray = _jtwfxwIds.split(",");
          var _arraySelected = new Array();
                 for(var i=0; i < tempArray.length; i++){
                  itmsDictWfxwStore.each(function(record){
                  if(record.data.wfxw == tempArray[i]){
         _arraySelected.push(record);
         }
                 });
   
                }
       itmsDictWfxwSM.selectRecords(_arraySelected,true);
      },this,{delay:1});//原来采用直接注册到监听里的方式,发现在数据加载完后,虽然数据已处于选中状态,但是复选框不显示√号,采用延迟(哪怕是1毫秒)后即显示,可能是extJS的bug

var itmsDictWfxwSM = new Ext.grid.CheckboxSelectionModel({
                      listeners: {
                          rowselect: function(sm, row, _record) {
             var _index = selectedWfxwStore2.getCount();
             selectedWfxwStore.insert(_index ,_record);
                          },
                          rowdeselect : function(sm, row, _record) {
             selectedWfxwStore.remove(_record);
                          }                         
                      }
                });

参考:http://fireinjava.iteye.com/blog/483922和http://www.iteye.com/problems/20