我应该在Sencha Touch 2中扩展Ext.app.Application类吗?

时间:2012-09-20 12:22:36

标签: extjs sencha-touch touch extend

我应该在Sencha Touch 2中扩展Ext.app.Application类吗? 我有几个应用程序常用的功能,例如:为应用程序中配置的所有商店执行某些操作。 如果是,我如何在app.js中启动应用程序?

1 个答案:

答案 0 :(得分:6)

我将回答 ExtJS 4.0.x / 4.1.x 和SenchaTouch 2.0.x / 2.1.x

您不应该展开Ext.app.Application

<强>为什么吗

您一次只能拥有一个应该(需要)始终配置的活动应用程序。通过致电Ext.application({...});来启动。

一如既往地存在这种方法(在两个框架中),然后允许您使用自己的实例。但是不推荐它!

需要什么?

基本上唯一需要的是在Ext.application方法中重新实现和扩展代码,以便它能够处理任何其他类Ext.app.Application。我将添加一个SenchaTouch示例,对于ExtJS,请参阅代码下方的ExtJS4.2部分。

SenchaTouch示例

application: function(appClass,config) {
    var appName = config.name,
        onReady, scope, requires;

    if (!config) {
        config = {};
    }

    if (!Ext.Loader.config.paths[appName]) {
        Ext.Loader.setPath(appName, config.appFolder || 'app');
    }

    requires = Ext.Array.from(config.requires);
    config.requires = [appClass];

    onReady = config.onReady;
    scope = config.scope;

    config.onReady = function() {
        config.requires = requires;
        Ext.create(appClass, config);

        if (onReady) {
            onReady.call(scope);
        }
    };

    Ext.setup(config);
},

对ExtJS 4.2的说明

Sencha宣布了ExtJS 4.2,它允许我们从Ext.app.Application

扩展