2014-10-07 35 views
1

我有一個問題,不知道這是一個錯誤還是我誤解了一些東西。我想要搜索具有特定類的組件。例如:Sencha Touch:使用ComponentQuery()和Down()搜索類組件

Ext.define('Test', { 
    xtype: 'Test', 
    cls: ['cat', 'dog'] 
}); 

我想找到該組件我在Ext.Containerthis.down('Test[cls~=cat]')創建(I使用~=因爲該組件具有多類)。但我得到undefinednull(不知道了)作爲結果。

With Ext.ComponentQuery.query('Test[cls~=cat]')我其實可以找到它。

這是爲什麼?我認爲down()Ext.ComponentQuery.query相同,區別在於它的搜索範圍不是全局的。

我使用的是當前版本的Sencha Touch。

回答

0

不,這不起作用。但是你可以使用

this.query('Test[cls~=cat]') 

,或者你使用這樣的:

Ext.ComponentQuery.pseudos.hasCls = function(items, cls) { 
    var i = 0, l = items.length, c, result = []; 
    for (; i < l; i++) { 
     var c = items[i]; 
     if (c._cls && c._cls.indexOf(cls) > -1) { 
      return c; 
     } 
    } 
    return undefined; 
}; 

,並調用它像:

this.down(".component:hasCls(cat)")