【问题标题】:How to iterate through all the classes defined in ExtJS application如何遍历 ExtJS 应用程序中定义的所有类
【发布时间】:2017-03-05 16:26:46
【问题描述】:

在单页 ExtJS 6 应用程序中,我需要扫描所有使用 Ext.define 方法声明的类,并找到那些实现特定 mixin 的类。为简单起见,我们假设我感兴趣的所有类都已加载,并且按需加载机制不适用。

似乎没有其他方法可以通过私有Ext.ClassManager.classes 属性进行迭代。有没有更清洁的替代品?

无论如何,上面给出了类名列表。如何判断对应的类是否实现了特定的mixin?

【问题讨论】:

  • 对于特定的你想迭代视图/控制器类?
  • 不,在大多数情况下,这些是从 Ext.Base 派生的通用类。

标签: extjs extjs6


【解决方案1】:
function getClassesByMixin(mixin){
    var classes=[];
    Ext.iterate(Ext.ClassManager.classes,function(className,c){
        if(c.prototype &&c.prototype.mixins &&  c.prototype.mixins[mixin]){
            classes.push(className);
        }
    });
    return classes;
}

Sencha fiddle

【讨论】:

  • 谢谢,西奥。我自己想出了几乎相同的解决方案。只是想知道为什么 Sencha 没有提供干净的反射 API
猜你喜欢
  • 1970-01-01
  • 2011-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多