问题
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>
...
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'
}]
});
}
});
EDIT
By the way, even running "official" /ext-5.0.1/examples/app/simple/simple.html
I get the same error. Why is that?
回答1:
Wrap the call to Ext.application
inside an Ext.onReady
block.
// 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'
}]
});
}
});
})
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.
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)
回答2:
Instead of
<script src="/ext-5.0.1/ext-all-debug.js"></script>
You should use
<script src="/ext-5.0.1/build/ext-all-debug.js"></script>
The second one contains all Components and Classes as expected.
来源:https://stackoverflow.com/questions/25038776/extjs-5-ext-application-is-not-a-function-why