2011-08-24 68 views
0

我在存儲過濾中遇到問題。我的過濾器功能正常工作,並按預期返回真/假,但最終所有記錄都被過濾掉了! xstore是對網格商店的參考。我也使用了主要的商店變量..但沒有運氣!任何幫助appriciated。過濾存儲中的ExtJs問題

xstore.filterBy(function(rec){ 

     app_rec = rec.get('APPNAME').toUpperCase(); //Record's value that needs to be checked' 

     Ext.each(elems,function(el){ //For each record, it checks 7 (dynamic) elements 
      //var ischecked = Ext.get(Ext.getCmp(el.id).teamName+'cb').dom.checked; 

      if(Ext.getCmp(el.id).teamName.toUpperCase() == app_rec) 
      {// If Element's attribute 'teamname' is matched then check if element's chkbox is chked/unched' 
       var ischecked = Ext.get(Ext.getCmp(el.id).teamName+'cb').dom.checked; //get the checkbox 
       //alert("app_rec: "+app_rec+"panelTeam: " + Ext.getCmp(el.id).teamName.toUpperCase()+"isChecked: "+ischecked); 
       if(ischecked) //if isChecked... keep record.. below alert if working as expected 
       { alert("return true"+"app_rec: "+app_rec+"panelTeam: " + Ext.getCmp(el.id).teamName.toUpperCase()+"isChecked: "+ischecked); 
        return true;} 
       else //Else avoid record 
       { //alert("return false"); 
        return false;} 
      } 

     }); 

感謝, 圖莎爾Saxena先生

回答

0

Ext.each是從一個普通的JavaScript不同的在循環中,您可以在每次通話中返回false停止迭代。 Ext.each文檔提到了這一點:

如果提供的函數返回false,則迭代停止,並且此 方法返回當前索引。

因此,當你在每次通話中返回,你不返回true/false來的filterBy功能像你期望的那樣,但對each功能。

儘量保持手柄上isChecked外的每個循環,然後返回真/假基於什麼發現每個函數內部:

// excluded your other code to highlight area around Ext.each call 

var isChecked = false; 

Ext.each(elems, function(el){ 
    if(Ext.getCmp(el.id).teamName.toUpperCase() == app_rec) { 
     ischecked = Ext.get(Ext.getCmp(el.id).teamName+'cb').dom.checked; 

     // can exit early if isChecked is true 
     if(isChecked){ 
      return false; // this will exit the Ext.each method 
     } 
    } 
}); 

// if this is true, filterBy will include the record 
return isChecked;