2013-01-23 20 views
1

我有一個簡單的問題,即使它給了我相當頭痛的問題。在EXT JS中獲取現場容器的孩子4

我有一個已經添加到它的一些無線電場場容器:但是

xtype  : 'fieldcontainer', 
          fieldLabel : 'Field type', 
          defaultType: 'radiofield', 
          defaults: { 
           flex: 1 
          }, 
          items: [ 
           { 
            boxLabel : 'Plain Text', 
            name  : 'plain-text', 
            inputValue: 'plain-text', 
            id  : 'plain-text' 
           }, { 
            boxLabel : 'Rich Text', 
            name  : 'html-text', 
            inputValue: 'html-text', 
            id  : 'html-text' 
           }, { 
            boxLabel : 'Time', 
            name  : 'time', 
            inputValue: 'time', 
            id  : 'time' 
           }, 
           { 
            boxLabel : 'Typed reference', 
            name  : 'typed-reference', 
            inputValue: 'typed-reference', 
            id  : 'typed-reference' 
           }, 
           { 
            boxLabel : 'Date', 
            name  : 'date', 
            inputValue: 'date', 
            id  : 'date' 
           } 

          ], 

          listeners: { 
           added: function(radiofield) { 
            ?? 

           } 

我幾乎嘗試了一切檢查radiofield對象,比如迭代其items.items陣列添加的項目,我只得到項目的整數值,而不是對象本身。我想迭代添加到容器的所有項目,以便在符合特定條件的無線電字段上設置選中的值。

回答

0

使用query([selector])

檢索通過選擇符合所有的後續組件。 使用此容器作爲其根執行Ext.ComponentQuery.query。

+0

我喜歡CD的答案,因爲實施起來很快。感謝您的意見! – Lasse

0

有什麼理由不使用RadionGroup?無論如何;項目類型Ext.util.MixedColletion它爲您提供的每個方法http://docs.sencha.com/ext-js/4-1/#!/api/Ext.util.AbstractMixedCollection-method-each

的請嘗試以下

// define a function within the scope of the fieldcontainer(instance) 
handlerFunction: functio(item) { 
    // item is the instance of your radiofield 
    // you can access any property or call any method 
    if (item.name === 'html-text') { 
     item.setValue('html-text'); 
    } 
} 

fieldcontainerInstance.items.each(handlerFunction,handlerFunctionScope); 
+0

你說得對,我把它改成了RadioGroup - 更有意義。 – Lasse

0

只需輸入item.query()來獲得它的所有項目。