2012-02-21 23 views
0

我正在使用ext js。 我有組合框,我選擇一個值,並使用此值作爲參數來獲取其他值(兩個值)。現在我想將它添加到變量中,以便在除組合框之外的其他位置使用它。我怎樣才能做到這一點?如何爲Combobox的選定值傳遞參數並從數據庫中獲取參數的值

var txtEP=new Ext.form.ComboBox({ 
      renderTo: "txtEP", 
      fieldLabel: 'End Point', 
      triggerAction: "all", 
      forceSelection: true, 
      mode:'local', 
      autoScroll: true, 
      allowBlank: false, 
      autoShow: true, 
      typeAhead:true, 
      store: genres, 
      valueField:'pincode', 
      displayField:'pincode', 
      emptyText:'Select a Start Point', 
      selectOnFocus:true, 
      listeners : { 
       'select' : function(){ 
       var selVal = this.getValue(); 
      //endpt(Global Variable) is the variable where i am trying to get this value. 
      endpt=store.load({url:'./genres1.php', params: {pincode: selVal}}); 
        alert(endpt); 
        } 
       } 
      //valueField: 'X,Y'  
     }); 

回答

0

你必須給它一個回調指定爲store.load一個配置,這是因爲當你將它馬上商店不包含任何數據。事情是這樣的:

var txtEP = new Ext.form.ComboBox({ 
    renderTo: "txtEP", 
    fieldLabel: 'End Point', 
    triggerAction: "all", 
    forceSelection: true, 
    mode:'local', 
    autoScroll: true, 
    allowBlank: false, 
    autoShow: true, 
    typeAhead:true, 
    store: genres, 
    valueField:'pincode', 
    displayField:'pincode', 
    emptyText:'Select a Start Point', 
    selectOnFocus:true, 
    listeners : { 
     'select' : function(){ 
      var selVal = this.getValue(); 
      store.load({ 
       url:'./genres1.php', 
       params: {pincode: selVal}, 
       callback: function(records) { 
        endpt = records; // here is where it is assigned 
       } 
      }); 
     } 
    } 
}); 

也意識到,那個「endpt」現在包含Ext.data.Model對象數組,所以你可以使用給出here提取你從他們需要的任何值的方法。

爲了回答您的評論:

Ext.data.Model有get方法。您將它傳遞給您想要獲取值的字段的名稱。在你的情況中,你提到某個地方/genres.php返回兩個值,如果數據返回爲一個記錄有兩個不同的列,如下所示:

column header:| value1 |值2

第1行: 'data1'| 「數據2」

您可以分配兩個這樣的回調函數返回的數據值的變量,說你被點名了你的變量firstValuesecondValue

firstValue = endpt[0].get('value1'); 
secondValue = endpt[0].get('value2'); 

相反,如果你的/genres.php返回數據爲兩個不同的行只用一個列標題是這樣的:

列標題:值

行1: 'DATA1'

行2: '數據2'

你可以指定數據變量是這樣的:

firstValue = endpt[0].get('value'); 
secondValue = endpt[1].get('value'); 
+0

首先感謝。但是,我現在如何使用Ext.data.Model對象的數組,請幫助新的這一點。 – Pari 2012-02-21 06:58:29

+0

@ user1220259我添加了一些如何去解決這個問題的例子 – Geronimo 2012-02-21 16:43:52

+0

@ user1220259如果這個問題對您有用,請不要忘記接受答案(左邊的複選標記) – Geronimo 2012-02-21 16:50:25

相關問題