【问题标题】:Hide / Show Ext.js compositefield with label in Ext.js 3.4在 Ext.js 3.4 中隐藏/显示带有标签的 Ext.js 复合字段
【发布时间】:2012-10-04 08:39:11
【问题描述】:

我正在尝试使用组合中的侦听器显示/隐藏 ext.js (xtype:"compositefield")。一切正常,除了复合字段的标签不会隐藏。如何选择整个复合字段 DOM 元素以便我可以在其上使用 .hide()/.show() ?

复合字段的代码:

xtype: 'compositefield',
                   labelStyle: 'width: 60px',
                   fieldLabel: 'Player 1',
                   id: "player_1_fields",
                   msgTarget: 'under',
                   items:[
                       {xtype: 'displayfield', value: 'Name',margins: '3 5 0 22'},
                       {xtype: 'textfield', name: 'props_name_1', width: 135},
                       {xtype: 'displayfield', value: 'Score',margins: '3 5 0 0'},
                       {xtype: 'numberfield', name: 'props_score_n1', width: 35}
                   ]

监听代码:

listeners: {
                                    select: function(combo, record, index) {
                                     if ( combo.getValue() == "2" ) 
                                                {
                                                Ext.getCmp("player_1_fields").getEl().hide();

                                                }
                                            else
                                                {
                                                Ext.getCmp("player_1_fields").getEl().show();

                                                }
                                    }
                                  }

【问题讨论】:

    标签: extjs extjs3


    【解决方案1】:

    试试这个代码:

    select: function(combo, record, index) {
        if ( combo.getValue() == "2" ) {
                Ext.getCmp("player_1_fields").getEl().up('.x-form-composite').hide();
        } else {
                Ext.getCmp("player_1_fields").getEl().up('.x-form-composite').show();
        }
    }
    

    Up 应该找到具有特定类的父级(并且您希望它是整个表单项的 ExtJs 类)。

    【讨论】:

    • 不,它也在 3.4 中,甚至在 2.1 文档中。这里是link to Element.up method in ExtJs 3.4
    • 抱歉快速错误的假设,我得到了:TypeError: Ext.getCmpup("..").up is not a function。 Up 必须在元素上使用,而不是在 getCmp 上。 ( Ext.getCmp("player_1_fields").getEl().up('.x-form-item').hide() )。感谢您的帮助!
    • 为什么不直接使用 CompositeField 的 setVisible 函数呢? docs.sencha.com/extjs/3.4.0/#!/api/…
    • @rockskull 因为 setVisible 在组件上它自己不会隐藏它的标签,我同意违反直觉,但我认为是这样的,因为标签渲染是在布局管理器内部完成的,所以从技术上讲标签不是组件本身。
    猜你喜欢
    • 2011-12-08
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    相关资源
    最近更新 更多