Extjs 5. Ext.application不是一个函数。为什么? [英] Extjs 5. Ext.application is not a function. Why?

查看:105
本文介绍了Extjs 5. Ext.application不是一个函数。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制台中收到错误: Ext.application不是一个函数。我的 index.html 文件包含以下代码:

I get an error in console: Ext.application is not a function. My index.html file contains this code:

...
<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 只有这个代码,从一个演示中获取:

While app.js has just this code, taken from one demo:

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 我也遇到同样的错误。为什么会这样?

By the way, even running "official" /ext-5.0.1/examples/app/simple/simple.html I get the same error. Why is that?

推荐答案

将呼叫转至 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'
        }]
      });
    }
  });
})

BTW需要的原因是ext-all-debug.js文件不包含所有ExtJS。它包含引导代码 - 知道如何获得一切的代码。应用程序代码的一部分一切。所以直到有机会运行,Ext.application不存在。

The reason this is necessary, BTW, is that the ext-all-debug.js files doesn't contain all of ExtJS. It contains the bootstrap code - the code that knows how to get everything else. Part of that "everything else" is the application code. So until that's had a chance to run, Ext.application doesn't exist.

您提到的门户网站示例的作用是因为它使用 sencha app build - microloader.js 。这将加载完整版本的ExtJS(或者说应用程序中使用的部件),因此Ext.application已经在使用时被定义了。 (与Sencha小提琴一样 - 您也不需要Ext.onReady)

The portal example you mention works because it uses the result of a sencha app build - the microloader.js. This loads up a full version of ExtJS (or rather, the parts used in the app), and thus Ext.application is already defined by the time it's used. (The same goes with Sencha Fiddle - you wouldn't need the Ext.onReady there either)

这篇关于Extjs 5. Ext.application不是一个函数。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆