2010-11-15 53 views
0

我是extJS的新手,并试图实现以下功能:Ext JS Dependent combo box

我有两个选择下拉菜单,使用extJS进行转换。我怎样才能确保如果选择了一个组合框中的值,另一个值应该设置回某个默认值?

谢谢。

编辑:代码至今:

Ext.onReady(function(){ 

var converted = new Ext.form.ComboBox({ 

    typeAhead: true, 
    triggerAction: 'all', 
    transform:'id_Select1', 
    width:600, 
    forceSelection:true, 
    emptyText:'Select' 

}); 

var convertedCdr = new Ext.form.ComboBox({ 
    typeAhead: true, 
    triggerAction: 'all', 
    transform:'id_select2', 
    width:600, 
    forceSelection:true, 
    emptyText:'Select' 
}); 
}); 

我使用ColdFusion查询数据库和填充下拉菜单:

<cfquery name="getData1" datasource="abc"> 
    SELECT * FROM table1 
</cfquery> 

<cfquery name="getData2" datasource="abc"> 
    SELECT * FROM table2 
</cfquery> 

<select name="select1" id="select1"> 
    <cfoutput query="getData1"> 
     <option value="#getData1.Id#">#getData1.name#</option> 
    </cfoutput> 
</select> 

<select name="select2" id="select1"> 
    <cfoutput query="getData2"> 
     <option value="#getData2.Id#">#getData2.name#</option> 
    </cfoutput> 
</select> 

回答

3

编辑 - 我没有使用CFM .. 。你需要弄清楚如何使用数据存储加载你的CF来使用这种技术。

您需要在组合中添加侦听select事件:

xtype: 'combo', 
id : 'firstComboID', 
listeners: { 
    select: function(combo, record, index) { 
    var selVal = Ext.getCmp('firstComboID').getValue(); 
    var secondCombo = Ext.getCmp('secondComboID'); 
    secondCombo.store.reload({params: {yourParameterName: selVal}}); 
} 

基本上你在这里做以下几点:

  1. 在第一个组合
  2. 获取选定的值
  3. 获取对第二个组合的数据存储的引用
  4. 使用第一个com中的选定值重新加载第二个组合框的存储博
+0

这里是我到现在为止 'Ext.onReady(函数(){VAR转换=新Ext.form.ComboBox({预输入代码:真实,triggerAction: '全部',转变:“id_Select1 ',width:600,forceSelection:true,emptyText:'Select'}}); var convertedCdr = new Ext.form.ComboBox({typeAhead:true,triggerAction:'all',transform:'id_select2',width:600,forceSelection:true,emptyText:'Select'}); }); 我有两个选择下拉填充从数据库:不知道如果combo.store会在我的情况下工作? – DG3 2010-11-15 18:39:56

+0

您可以使用所见即所得的编辑器中的代码格式编辑您的问题与源代码吗? 你的组合框从哪里获取他们的数据?我没有看到任何配置选项。 – 2010-11-15 18:58:49

+0

我用我的代码编辑了我最初的问题。谢谢。 – DG3 2010-11-15 19:05:16