2012-02-21 92 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