extjs - 选中复选框时显示组合框 - Extjs

标签 extjs checkbox combobox extjs4

我已经设置了一个复选框和一个组合框,并且我正在尝试设置一个功能 - 当用户选中该复选框时,组合框必须出现。我是 extjs 新手,在设置此功能的函数时遇到问题。

Ext.onReady(function() {

var tests = [
    ['Test1'],
    ['Test3'],
    ['Test2']
];
Ext.define('Testfile.model.Test', {
    extend: 'Ext.data.Model',
    fields: ['test']
});
var testsStore = new Ext.data.Store({
    model: 'Testfile.model.Test',
    proxy: {
        type: 'memory',
        reader: {
            type: 'array'
        }
    },
    data: tests
});
var form = Ext.create('Ext.form.Panel', {
    renderTo: document.body,
    bodyPadding: 10,
    width: 550,
    style: 'margin:16px',
    height: 300,
    title: 'Testing example',
    items: [{

          xtype: 'checkbox',
          name: 'system',
          boxLabel: 'Production (PACTV)',
          iputValue: 'production',

        listeners: {
            check: function (checkbox, isChecked) {
                    var sample = Ext.getCmp('secondComboID');
                }

        }
    }, {
        xtype: 'combobox'
        fieldLabel: 'Select Test',
        id: 'secondComboID',
        store: testsStore,
        valueField: 'id',
        displayField: 'test',
        typeAhead: true,
        forceSelection: true,
        allowBlank: false,
        editable: true,
        triggerAction: 'all',
        lastQuery: ''
    }]
});
Ext.getBody().add(me.form);

})

有人可以建议修复脚本吗?

最佳答案

我将使用change事件:http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.Checkbox-event-change

listeners: {
    change: function(checkbox, newValue, oldValue, eOpts) {
        var combo = checkbox.up('form').down('combobox');
        if (newValue) {
            combo.show();
        } else {
            combo.hide();
        }
    }
}

此外,请注意层次导航方法 up()down() 的使用。使用这些(或其他相关方法)来查找组件比使用硬编码组件 ID 更可取。

这是您的代码的工作示例: https://fiddle.sencha.com/#fiddle/ua

关于extjs - 选中复选框时显示组合框 - Extjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323863/

相关文章:

silverlight - Silverlight 中的组合框显示值

extjs - Ext JS 4.2.1 部署

extjs - Sencha CMD 构建错误 com.sencha.exceptions.ExProcess : compass process exited with non-zero code : 1

checkbox - 拦截 VueJS 中的复选框更改事件

java - ComboBox 选项在调整舞台大小时获得 margin

android - 在 qt (qml) 中更改原生样式组合框的文本颜色

javascript - 如何处理 Sencha 中的旋转或方向?

javascript - 为什么即使使用 vtype 的电子邮件验证失败,提交按钮在 extjs 中仍然有效?

javascript - jquery 当未选中复选框时隐藏文本框

javascript - 设置具有特定值的复选框