2012-12-19 30 views
1

如何通過具有條件,即當前存儲器大小爲0。如何發送AJAX請求僅當存儲大小是0

基本上我具有級聯兩個遠程組合框和兩者都是懶惰地發送AJAX請求組合框加載(這種行爲不能更改)

我發現即使第二個組合框是基於第一組合框事件upoun擴張級聯它使AJAX調用服務器(僅限第一擴張雖然)

querymode本地和自動加載選項不起作用,因爲它在創建存儲時在加載頁面時加載組合框。

下面給出的是代碼片段。

xtype: 'combo',id='firstcombo', name: 'DEFAULT_VALUE' ,minChars:2, value: decodeHtmlContent('') ,width:200 ,listWidth:500, resizable: true, 
valueField : 'id', displayField: 'id', pageSize: 15,forceSelection:true, enableKeyEvents: true, 
store: new Ext.data.Store({reader: new Ext.data.CFQueryReader({id: 'NAME', 
      fields:[{name:'id', mapping:'id'}]}), 
      fields: [{name:'id', mapping:'id'}], 
      url:'server/ajax/Params' 
      } 

}), 
listeners : { 
     select:function(combo, record, index) { 
      this.setRawValue(decodeHtmlContent(record.get('id'))); 
      cascadeFields(); 
     } 



xtype: 'combo',id='secondcombo', name: 'DEFAULT_VALUE' ,minChars:2, value: decodeHtmlContent('') ,width:200 ,listWidth:500, resizable: true, 
valueField : 'id', displayField: 'id', pageSize: 15,forceSelection:true, enableKeyEvents: true, 
store: new Ext.data.Store({reader: new Ext.data.CFQueryReader({id: 'NAME', 
      fields:[{name:'id', mapping:'id'}]}), 
      fields: [{name:'id', mapping:'id'}], 
      url:'server/ajax/Params', 
      baseParam:{valuefirst:''} 
      }, 
      listeners: { 

       beforeload: function(store, options) { 
        var value = Ext.getCmp('fistcombo').value; 
        Ext.apply(options.params, { 

           valuefirst:value 
          }); 


       }, 

}), 
listeners : { 
     select:function(combo, record, index) { 
      this.setRawValue(decodeHtmlContent(record.get('id'))); 
     } 


function cascadeFields() 
{ 

    var combo = Ext.getCmp('secondcombo'); 

    if(combo.store) 
    { 

    var store = combo.store; 


    combo.setDisabled(true); 
    combo.clearValue(''); 
    combo.store.removeAll(); 
    combo.store.load();   
    combo.setDisabled(false); 

    } 
} 

回答

1

要延長只是你的代碼,你可以像這樣

listeners: { 
    beforeload: function(store, options) { 
     if (store.getCount() > 0) { 
      return false; // will abort the load operation. 
     } 
     var value = Ext.getCmp('fistcombo').value; 
     Ext.apply(options.params, { 
      valuefirst:value 
     }); 
    } 
} 

,因爲你沒有指定這個沒這應該都是一樣的ExtJS的3.x和ExtJS4.x。但我想你正在使用3.x

如果這掛在組合給我反饋,因爲還有另一種,但有點複雜的方式。

+0

我在17秒後發佈了完全相同的解決方案。 +1 – lontivero

+0

@lontivero呃感謝upvoting和+1在其他地方;) – sra

+0

謝謝你爲我工作。 – user1913742