-
8 Nov 2012 5:02 AM #1
Answered: Extend Ext.Application
Answered: Extend Ext.Application
Hi,
based on the pandora example I tried to extend Ext.app.Application like shown in the section "Deriving from Ext.app.Application" here. I get something like this:
But I get an error saying 'Error: this.callParent() was called but there's no such method (onBeforeLaunch) found in the parent class (Ext.app.Controller)' on line 'Ext.application > launch > me.callParent'Code:Ext.define('AbstractApplication', { extend: 'Ext.app.Application', constructor: function (config) { config = config || {}; Ext.apply(this, config); var me = this; me.callParent(config); }, launch: function () { var me = this; me.initBar(); }, bar: function () { console.log('bar called'); } }); Ext.application({ extend: 'AbstractApplication', name: 'Pandora', autoCreateViewport: true, models: ['Station', 'Song'], stores: ['Stations', 'RecentSongs', 'SearchResults'], controllers: ['Station', 'Song'], launch: function () { var me = this; me.callParent(); } });
If I do it the way described here withit works faultless. May somebody please tell me why the example from the docs is not working or what I'm doing wrong?Code:Ext. onReady
-
Best Answer Posted by vietits
Ext.application() is in fact will:
1. Load Ext.app.Application class.
2. On Ext.ready, it will create an instance of Ext.app.Application.
So with your code:Code:Ext.application = function(config) { Ext.require('Ext.app.Application'); Ext.onReady(function() { new Ext.app.Application(config); }); };
(1): This line has no effect because Ext.app.Application has no config named 'extend'.Code:Ext.application({ extend: 'AbstractApplication', // (1) name: 'Pandora', autoCreateViewport: true, models: ['Station', 'Song'], stores: ['Stations', 'RecentSongs', 'SearchResults'], controllers: ['Station', 'Song'], launch: function () { var me = this; me.callParent(); // (2) } });
(2): This line cause the error you mentioned in your post. Because Ext.app.Application is extended from Ext.app.Controller so this line will call Ext.app.Controller.launch(). However, because Ext.app.Controller does not define launch() method so it will cause error.
-
8 Nov 2012 5:40 AM #2
Ext.application() is in fact will:
1. Load Ext.app.Application class.
2. On Ext.ready, it will create an instance of Ext.app.Application.
So with your code:Code:Ext.application = function(config) { Ext.require('Ext.app.Application'); Ext.onReady(function() { new Ext.app.Application(config); }); };
(1): This line has no effect because Ext.app.Application has no config named 'extend'.Code:Ext.application({ extend: 'AbstractApplication', // (1) name: 'Pandora', autoCreateViewport: true, models: ['Station', 'Song'], stores: ['Stations', 'RecentSongs', 'SearchResults'], controllers: ['Station', 'Song'], launch: function () { var me = this; me.callParent(); // (2) } });
(2): This line cause the error you mentioned in your post. Because Ext.app.Application is extended from Ext.app.Controller so this line will call Ext.app.Controller.launch(). However, because Ext.app.Controller does not define launch() method so it will cause error.
-
8 Nov 2012 5:57 AM #3
hm ok, thank you vietits
Though why does the docs give this
as an example for extending Ext.app.Application? Most of the times I look at the docs, the given examples don't work. This is not a quality mark.Code:Ext.define('MyApp.app.Application', { extend: 'Ext.app.Application', ... }); Ext.application({ extend: 'MyApp.app.Application', name: 'Blog', models: ['Post', 'Comment'], controllers: ['Posts', 'Comments'], launch: function() { ... } });
-
8 Nov 2012 3:42 PM #4
What Ext version do you use? The document on the web is for 4.1.3. Maybe this is applied for Ext 4.1.2 or Ext 4.1.3 but this is not applied for Ext 4.1.1a or earlier.
-
8 Nov 2012 11:15 PM #5
this could be the reason, I'm using 4.1.1. Is there a doc especially for 4.1.1?
-
9 Nov 2012 12:06 AM #6
If you downloaded and unziped Ext 4.1.1, then the documents is under "docs" folder.


Reply With Quote