我在控制台中收到错误: 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>    
...

尽管 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'
        }]
    });
}
});

编辑

顺便说一句,甚至运行“官方” /ext-5.0.1/examples/app/simple/simple.html 我犯了同样的错误。这是为什么?

有帮助吗?

解决方案

将通话转接至 Ext.application 里面一个 Ext.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'
        }]
      });
    }
  });
})

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

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

其他提示

代替

<script src="/ext-5.0.1/ext-all-debug.js"></script>

你应该使用

<script src="/ext-5.0.1/build/ext-all-debug.js"></script>

第二个包含预期的所有组件和类。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top