javascript - 在 extjs 中显示隐藏元素

标签 javascript extjs

我正在尝试根据下拉选择中的选择来显示和隐藏 radio 组。因此,如果我选择东芝,则只会出现东芝型号,否则,如果我选择惠普,则只会出现惠普型号。现在该功能正在运行,但是在开始选择任何东西之前,两种型号(hp 和 toshiba)都在显示,但是我想要它以便只有 toshiba 型号在开始时显示。我尝试为 hp 模型提供 hidden:true 属性。但是当选择 hp 时,模型不再出现。关于如何在一开始只显示一个模型有什么想法吗?

toshibatypes = Ext.create('Ext.form.Panel', {
        xtype: 'radiogroup',
        defaultType: 'radio', 
        layout: 'hbox',
        border:false,
        id: 'toshiba',
        width:'100%',

        items: [ 
        {
            checked: true,
            boxLabel: 'Toshiba 1',
            name: 'toshibas',
            inputValue: 'toshiba1',
            xtype:'radiofield'
        }, 
        {
            boxLabel: 'Toshiba 2',
            name: 'toshibas',
            inputValue: 'toshiba2',
            xtype:'radiofield'
        }
    ]
});



hptypes = Ext.create('Ext.form.Panel', {
        xtype: 'radiogroup',
                defaultType: 'radio', 
            layout: 'hbox',
        border:false,
        id: 'hp',
        width:'100%',

        items: [ 
        {
            checked: true,
            boxLabel: 'HP 1',
            name: 'hps',
            inputValue: 'hp1',
            xtype:'radiofield'
        }, 

        {
            boxLabel: 'HP 2',
            name: 'hps',
            inputValue: 'hp2',
            xtype:'radiofield'
        }]
});



    laptoptypes = Ext.create('Ext.form.ComboBox', {
        store: laptops,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'abbr',
        editable:false,
        width: 100,
        listeners: { 
       select: function() {
       var iComboValue = laptoptypes.getValue();
           switch(iComboValue) {
            case "toshibatypes" : 
            {
                Ext.get("toshiba").show();
                Ext.get("hp").hide();

                break;
            }
            case "hptypes" : 
            {
                Ext.get("hp").hide();
                Ext.get("toshiba").show();

                break;
            }

        } 
       }
       }
    });

最佳答案

如果您在 View 声明中配置隐藏,您可以使用 setHidden( boolean ) .

var iComboValue = laptoptypes.getValue();

Ext.get("toshiba").setHidden(iComboValue !== 'toshibatypes');
Ext.get("hp").setHidden(iComboValue !== 'hptypes');

关于javascript - 在 extjs 中显示隐藏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32814588/

相关文章:

javascript - Javascript 函数必须在调用之前定义吗?

javascript - 检查网格插件 ExtJs 中的新元素

java - ExtJs Combobox 显示字段编码

javascript - ExtJS - 编辑行调用函数时更新按钮

javascript - 如何使用 React 和 JavaScript 将 .txt 文件转换为 JSON

javascript - 如何在单页应用程序中使用窗口onload?

javascript - Edge 中的异步滚动 (APZ) 卡顿且有问题;不在 IE 或其他浏览器中

javascript - ExtJs 5 图表问题

javascript - ExtJS 4 在树中隐藏根节点的问题

javascript - JSON 响应打印 HTML 而不是消息