【问题标题】:ExtJS application not looking in the correct app folderExtJS 应用程序没有在正确的应用程序文件夹中查找
【发布时间】:2014-04-12 06:40:19
【问题描述】:

在这个tutorial 中,有一段代码如下:

Ext.require('Ext.app.Application');

var Application = null;

Ext.onReady(function() {
    Application = Ext.create('Ext.app.Application', {
        name: 'AM',

        controllers: [
            'Users'
        ],

        launch: function() {
            //include the tests in the test.html head
            jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
            jasmine.getEnv().execute();
        }
    });
});

对我来说,当应用程序正在寻找应用程序代码时,这会导致 404。

GET http://localhost:8000/AM/controller/Users.js?_dc=1394340001581 404 (File not found)

为什么它使用应用程序名称 (AM) 而不是像往常一样使用“app”文件夹?我尝试直接设置“appFolder”配置也无济于事。当我使用

正常创建应用程序时,它工作正常
Ext.application({
    name: 'AM',

    // automatically create an instance of AM.view.Viewport
    autoCreateViewport: true,

    controllers: [
        'Users'
    ]
});

我正在使用来自根应用程序目录(index.html 和 app.js 所在的位置)的简单 http 服务器为应用程序提供服务,并使用 extjs 4.2.1.883。

【问题讨论】:

  • 因为Ext.application 不仅仅是启动一个实例。您甚至可以在Ext-more.js 的第 1420 行附近看到它的来源。
  • 我讨厌这样没有意义的错误。然而应该注意的是,当使用 MVC 模式时,最好不要在 Ext.onReady 函数中启动您的应用程序。我在几个线程中阅读了此内容,但找不到原因。
  • 我能够解析 Ext 示例资源,我只需要确保示例中的目录结构正确嵌套在我试图让 jasmine 进入的现有、正在运行的应用程序中。实际上验证应用程序启动并没有那么幸运,但是 Extjs 主要版本 = 4 测试运行良好。

标签: javascript extjs model-view-controller extjs4


【解决方案1】:

这是通常如何配置路径映射:

Ext.Loader.setConfig({
    enabled: true,
    paths: {
        'AM': 'app'
    }
});

【讨论】:

    【解决方案2】:

    我从来不知道为什么它对我不起作用,但为了继续学习本教程,我只是使用了 Ext.application 并在启动时将应用程序分配给一个全局变量,即:

    Ext.application({
        requires: ['Ext.container.Viewport'],
        name: 'AM',
        controllers: [
            'Smiles'
        ],
        autoCreateViewport: false,
    
        launch: function() {
            window.Application = this;
        }
    });
    

    【讨论】:

      【解决方案3】:

      您必须设置 appFolder 例如:

      Ext.application({
          name: 'AM',
          appFolder: "Physical path of appfolder",
          autoCreateViewport: true, 
          controllers: [
              'Users'
          ]
      });
      

      为上述类创建对象。您将获得控制器的正确路径

      【讨论】:

      • 我尝试设置 appFolder,但没有任何改变。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多