2

如果 Ext.application 具有以下控制器:

Ext.Loader.setConfig({enabled:true});

Ext.application({        
    name: 'MyApp',
    appFolder: 'app',

    controllers: [
        'Ctrl1',
        'Ctrl2'
    ],

    launch: function() { ... }
});

它是否还应该包括该controllers部分中的控制器requires,即添加

requires: [
    'MyApp.controller.Ctrl1',
    'MyApp.controller.Ctrl2'
],

在上面的类中?

4

2 回答 2

4

最简洁的答案是不。

长答案是controllers,models和configsviewsstores转换为requires. 具有魔力的位在Ext.app.Controller类中:

onClassExtended: function(cls, data, hooks) {
    var Controller = Ext.app.Controller,
        className, namespace, onBeforeClassCreated, requires, proto, match;

    className  = Ext.getClassName(cls);
    namespace  = Ext.Loader.getPrefix(className) ||
                 ((match = className.match(/^(.*)\.controller\./)) && match[1]);

    if (namespace && namespace !== className) {
        onBeforeClassCreated = hooks.onBeforeCreated;
        requires = [];

        hooks.onBeforeCreated = function(cls, data) {
            proto = cls.prototype;

            Controller.processDependencies(proto, requires, namespace, 'model', data.models);
            Controller.processDependencies(proto, requires, namespace, 'view', data.views);
            Controller.processDependencies(proto, requires, namespace, 'store', data.stores);
            Controller.processDependencies(proto, requires, namespace, 'controller', data.controllers);

            // this is the line to look at!!!
            Ext.require(requires, Ext.Function.pass(onBeforeClassCreated, arguments, this));
        };
    }
},

您的应用程序只是一个Ext.app.Application继承自的类Ext.app.Controller;因此controllers配置也转换为requires.

于 2013-02-09T00:41:33.377 回答
2

不,这没有必要。app.js这是我现在正在使用的工作示例:

Ext.Loader.setConfig({enabled:true});
Ext.Loader.setPath('Ext.ux', '../extjs/examples/ux');

Ext.application({
    name: 'FPPP',

    autoCreateViewport: true,

    controllers: [
        'Main',
        'List',
        'Report'
    ]

});

还有Sencha MVC 指南

于 2013-02-07T19:01:02.570 回答