2012-04-25 53 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