Extjs 5. Ext.application不是一个函数.为什么?

Jac*_*ian 5 extjs extjs5

我在控制台中收到错误:Ext.application is not a function.我的index.html文件包含以下代码:

...
<link rel="stylesheet" type="text/css" href="/ext-5.0.1/packages/ext-theme-neptune/build/resources/ext-theme-neptune-all.css" />
<script src="/ext-5.0.1/ext-all-debug.js"></script>    
<script type="text/javascript" src="app.js"></script>    
...
Run Code Online (Sandbox Code Playgroud)

虽然app.js只有这个代码,取自一个演示:

Ext.application({
name: 'AM',
appFolder: 'app',
launch: function() {
    Ext.create('Ext.container.Viewport', {
        layout: 'fit',
        items: [{
                xtype: 'panel',
                title: 'Users',
                html : 'List of users will go here'
        }]
    });
}
});
Run Code Online (Sandbox Code Playgroud)

编辑

顺便说一句,即使运行"官方" /ext-5.0.1/examples/app/simple/simple.html我也会得到同样的错误.这是为什么?

Rob*_*ins 2

将调用包装到块Ext.applicationExt.onReady

// app.js
Ext.onReady(function() {
  Ext.application({
    name: 'AM',
    appFolder: 'app',
    launch: function() {
      Ext.create('Ext.container.Viewport', {
        layout: 'fit',
        items: [{
          xtype: 'panel',
          title: 'Users',
          html : 'List of users will go here'
        }]
      });
    }
  });
})
Run Code Online (Sandbox Code Playgroud)

顺便说一句,这是必要的原因是 ext-all-debug.js 文件不包含所有 ExtJS。它包含引导代码 - 知道如何获取其他所有内容的代码。“其他一切”的一部分是应用程序代码。因此,在有机会运行之前,Ext.application 并不存在。

sencha app build您提到的门户示例之所以有效,是因为它使用 a - the的结果microloader.js。这会加载 ExtJS 的完整版本(或者更确切地说,应用程序中使用的部分),因此 Ext.application 在使用时已经定义。(Sencha Fiddle 也是如此 - 你也不需要 Ext.onReady)

  • 好吧,包装在 Ext.onReady 内部没有任何效果 (2认同)