2013-10-09 21 views
0

即時使用extjs3。我的問題是使用ajax從服務器端加載商店。如下當在網格中檢查多行時,Ext.grid.CheckboxSelectionModel沒有返回正確的id值

var store_dept = new Ext.data.JsonStore({    
       totalProperty:'totalcount', 
       root:'rows_dept', 
       autoLoad:true, 
       url: '<%=getResultURL.toString()%>', 
       fields:[ 

         { name:'name'}, 
         { name:'id'}, 
         { name:'address'} 
         ] 

      }); 

var sm_dept = new Ext.grid.CheckboxSelectionModel(

         { 
          singleSelect: false, 
          checkOnly: false, 
          listeners: { 

           selectionchange: function(sm_dept) { 


           } 
          } 
         } 

       ); 

現在即時得到這樣的IM格式化渲染器列

function renderBufferResult_dept(value, p, record){ 

    return String.format('<div style="white-space:normal !important;"><b>{1}</b><br/>{3}<br/>{2}<br/></div>',value,record.data.name,record.data.address,record.data.id); 
} 

電網碼的響應是:

var grid_dept= new Ext.grid.GridPanel({ 
       id:'resgriddept',    
       width:210, 
       height:300, 
       title:'Additional Notification', 
       store: store_dept, 
       trackMouseOver:false, 
       disableSelection:true, 
       loadMask: true, 
       sm:sm_dept, 
       // grid columns 
       columns:[ 
         sm_dept, 
         {     
        header: "Details", 
        dataIndex: 'id', 
        width:210,     
        sortable: true, 
        renderer:renderBufferResult_dept 
       } 
       ] , 

       buttons: [ 
         { 
          text:'Export To Excel', 
          handler: function() 
          { 


           if(property_list!=''){ 
            /* var prop_list=''; 
            for(var i=0 ;i<sm.selections.getCount();i++){ 
             prop_list =prop_list+ sm.selections.get(i).data.id+','; 

            } */ 
            window.open('<%=getxlFileURL%>'+'&id_list='+property_list); 

           }else{ 
            alert('Select propert to Export'); 
           } 
          } 


         },{ 

          text:'Generate Letter', 
          handler: function() 
          { 



             var dept_id_list = '0,'; 
             if(sm_dept.selections.getCount()>0){ 
              alert('cont select'); 
             for(var j=0 ;j<sm_dept.selections.getCount();j++){ 
              alert("id "+sm_dept.selections.get(j).data.id); 
              dept_id_list = dept_id_list+sm_dept.selections.get(j).data.id+','; 
              alert('id with templist '+dept_id_list); 
             } 
            } 
             window.open('<%=getreportsURL%>'+'&id_list='+property_list+'&dept_id_list='+dept_id_list); 


          } 

         }], 
       buttonAlign:'center' 

      });//End Of Grid 
      // render it  
      grid_dept.render('res-grid-dept'); 
      store_dept.load(); 

問題是當我打生成字母鍵,被檢查的行(1,2,3)的id就像0,1,1,2,當它在警報中必須像0,1,2,3一樣。

回答

0

這是因爲您使用get方法MixedCollection而您應該使用itemAt。在API中,你可以看到這個方法返回與傳遞的鍵(在你的情況下爲ID)OR索引相關的項目,並且該鍵優先於索引。所以,當你傳遞0時,這被視爲索引,因爲你沒有這樣的密鑰,並且索引id是1.但是當你傳遞1時,它被視爲key(換句話說就是id),所以它返回item ID 1.

替換alert("id "+sm_dept.selections.get(j).data.id);alert("id "+sm_dept.selections.itemAt(j).data.id);,你會很好。