ExtJS组合框加载和禁用

4
我将问题总结如下。
我使用一个表单来编辑用户信息,这些信息从数据库中加载(我通过JSONStore获取这些值)。
我想根据另一个组合框的加载值启用/禁用组合框。
例如:如果组合框1的加载值= 0,则禁用组合框2。
- 如果我加载组合框1 = 1,组合框2 = 12:一切正常 - 如果我加载组合框1 = 0,组合框2 = 15:禁用组合框2
有什么想法吗?谢谢
2个回答

2
像这样的侦听器应该可以完成这项工作:
formEditUser.getForm().on('actioncomplete',function(form,action) {
  if(combo1.getValue() == 0) {
    combo2.disable();
  } else if (combo1.getValue() == 1) {
    combo2.enable();
  }
})

更改事件可能不会在交互更改的情况下触发。 - Lloyd
我现在明白你的意思了,尽管不是很清楚 OP 所说的“值加载到组合框”具体指什么。如果他的意思是将值加载到 JsonStore 中,则可以使用 JsonStore 的 load 事件来实现。 - Mchl
我正在处理类似的代码...但它似乎不起作用。如果我尝试像这样做: formEditUser.getForm().on('actioncomplete',function(form,action) { var comboFaculties = Ext.getCmp('comboFacultiesPrereg'); alert(comboFaculties.getId()); alert(comboFaculties.getValue()); }你知道会发生什么吗?我可以看到元素的ID,但值为空。我尝试了delay:1000,但没有帮助。我猜问题在于当事件actioncomplete被触发时,组合框还没有其值。 - Danilo
奇怪..如果是这样,您可能想要将success处理程序添加到您的加载命令中,然后查看会发生什么:formEditUser.getForm().load({ url: '', success: function(form,action) {}, ...) - Mchl
顺便提一下:在这个函数中,你可以检查action.result来直接获取来自服务器响应的值,而不是从表单字段中获取。 - Mchl
显示剩余3条评论

0
工作的代码片段:
enter code here
                                           {xtype: 'fieldset',
                                            items: [{xtype: 'combo',
                                                     hiddenName: 'category[line]',
                                                     fieldLabel: 'Category',
                                                     store: categories,
                                                     emptyText: 'Select',
                                                     triggerAction: 'all',
                                                     mode: 'local',
                                                     displayField: 'category_name',
                                                     valueField: 'id',
                                                     anchor: '50%',
                                                     listeners:{
                                                        select:{fn:function(thisCombo, value) {
                                                            var combo = Ext.getCmp('combo-subcats');      
                                                                combo.enable();
                                                                //combo.clearValue();
                /* category is part of the json data inside the subcat. So the first select choose the category - then filter out only that bit and populate the subcat combo. Make sense?                   */                         combo.store.filter('category', values.data['category']);
                                                            }}
                                                        }
                                                    },
                                                    {xtype: 'combo',
                                                     hiddenName: 'subcats[line]',
                                                     disabled: true,
                                                     id: 'combo-subcats',
                                                     fieldLabel: 'Sub Cat',
                                                     store: getSubcatsStore(),
                                                     emptyText: 'Select',
                                                     triggerAction: 'all',
                                                     mode: 'local',
                                                     displayField: 'name',
                                                     valueField: 'id',

                                                     anchor: '50%',
                                                     lastQuery: '' //<-- this is what makes it work.
                                                    },

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接