2012-04-25 51 views
1

我试图选择位于面板中的多个对象(2个标签& 2 textfields)。我给了这些组件一个属性(changeVisibility:true)。Extjs 4中的组件选择器

所以我在这里试图完成的事情非常简单:当用户选中复选框时,具有属性(changeVisibility:true)的所有组件都应该变为不可见。所以在我的控制器中,我试图选择这些组件,但我无法完成这个目标。

非常感谢帮助!我的面板

代码:

Ext.define('Edocs.view.wizard.card-2.content.mobile-password.Panel', { 
extend : 'Ext.FormPanel', 
alias : 'widget.mobilePassword', 
layout : { 
    type : 'vbox', 
    pack: 'center' 
}, 
bodyStyle:{"background-color":"beige"}, 
border:false, 
defaults:{ 

    width: '100%'  
}, 

items: [{   
    xtype   : 'checkboxfield', 
    boxLabel  : 'Enable mobile (iphone) accesibility', 
    boxLabelAlign : 'before', 
    name   : 'enableMobile', 
    inputValue  : '1', 
    id    : 'cbxMobile', 
    itemId   : 'cbxMobile' 

},{ 
    xtype: 'label', 
    text: "Please enter a password to connect to the platform by mobile (iphone/ipad)", 
    style: 'font-weight:bold;', 
    changeVisibility :true 
},{ 
    xtype: 'textfield', 
    name: 'mobilePassword', 
    id: 'txtMobilePassword', 
    inputType: 'password' , 
    changeVisibility :true 
    //width: '100%' 
},{ 
    xtype: 'label', 
    text: "Confirm password", 
    style: 'font-weight:bold;', 
    changeVisibility :true 
}, 
{ 
    xtype: 'textfield', 
    name: 'mobilePasswordConfirm', 
    itemId: 'txtMobilePasswordConfirm', 
    inputType: 'password' , 
    vtype: 'password', 
    initialPassField: 'txtMobilePassword', 
    changeVisibility :true 
}], 


initComponent : function() { 

    Ext.apply(this, {}) 
    this.callParent(arguments); 
} 
}); 

这是在我的控制器功能(该功能被称为上的复选框的更改事件):我遇到麻烦

addMobilePassword : function(checkbox) { 
    var items = checkbox.up().down('mobilePassword[changeVisibility=true]'); 
    if (checkbox.checked){ 
     for (var i in items){ 
      items[i].setVisible(false); 
     } 
    } 
} 

这个选择器:

var items = checkbox.up().down('mobilePassword[changeVisibility=true]'); 

如果任何人都可以给我一些关于如何选择的建议e组件。

谢谢!

+0

你试过[checkbox.up().query( 'mobilePassword [changeVisibility =真]')](HTTP://文档.sencha.com/EXT-JS/4-0 /#!/ API/Ext.container.AbstractContainer法查询)? – 2012-04-25 08:47:23

+0

刚刚尝试过,并没有工作... – Fbo 2012-04-25 08:55:24

+0

我知道,如果组件只会是标签,这应该工作:var items = checkbox.up()。down('label [changeVisibility = true]'); – Fbo 2012-04-25 08:58:25

回答

4

down()会发现容器的第一个匹配的后裔。所以,我想你应该尝试:

checkbox.up().down('mobilePassword').query('label[changeVisibility], textfield[changeVisibility]') 

或简短

checkbox.up().query('label[changeVisibility], textfield[changeVisibility]') 
+0

这个工作!Thx很多! – Fbo 2012-04-26 08:12:51

+0

只是一句话,要得到所有组件与changeVisibility属性,无论它们的类型如何,您也可以使用:'.query('* [changeVisibility]')' – avidenic 2015-05-07 12:53:34

0

尝试query('[changeVisibility=true]')

+0

不工作:(:(顺便说一句,它应该是Ext.query,因为如果发生错误如果你只需要键入查询) – Fbo 2012-04-25 10:37:58

+0

好吧......你应该在查询方法之前仍然使用'checkbox.up()。'我试图告诉你 - 如果你在'[]之前指定'mobilePassword',它会尝试寻找类型为mobilePassword的物件不是你想要的 – sha 2012-04-25 11:58:52

+0

抱歉误会,但它仍然没有工作..我试了一下没有任何运气 – Fbo 2012-04-25 12:32:24