2012-08-31 48 views
1

我在Extjs中创建了一个组合框,其中显示了报告的名称,当用户选择任何报告时,应该发布报告的后端ID。我无法获得报告的身份证件。我正在使用商店来填充组合框中的数据。如何在ExtJs中获取组合框的valueField的值

我创建像

Ext.define('Report', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     {name: 'ReportId', type: 'int'}, 
     {name: 'DisplayName', type: 'string'} 
    ] 
}); 

存放在ExtJS的模型就像

var reportStore = Ext.create('Ext.data.Store', { 
    model: 'Report', 
    autoLoad: true, 
    proxy: { 
     type: 'ajax', 
     url: 'reportlist.json' 
}); 

组合框像

var comboReports = Ext.create('Ext.form.field.ComboBox', { 
    displayField: 'DisplayName', 
    valueField: 'ReportId', 
    fieldLabel: 'Report', 
    store: reportStore, 
    queryMode: 'local', 
    emptyText: 'Select a report', 
    selectOnFocus: true, 
    listeners: { 
      select: function(combo, selection) { 
       if (combo.getValue()) { 
     //showData(reportId); here i want the id of seleted report to passed. 

       } 
      } 
     } 
    }); 

回答

7

其实combo.getValue()返回所选项目的reportId。 showData(combo.getValue());是你需要的。

+0

不,它不工作.............当我尝试提醒值Combo.getValue()它显示空白,我使用这个命令Ext.Msg.alert(combo.getValue ()); ...........它显示空白 – Popeye

+1

我得到我的错误,我需要做Ext.Msg.alert(combo.getValue()。toString()); – Popeye