PDA

View Full Version : [CLOSED] Cannot add additional function for init() function in a controller



metas
14 Mar 2012, 11:38 PM
init: function() {

this.control({
...
//Designer2.x support coding here now.
});
//But cannot support coding here!
}

aconran
15 Mar 2012, 6:42 AM
Go to Code View, in the dropdown at the top left change the controller to init.

Code that you add here will be placed directly after this.control() in the init block.

Phil.Strong
16 Mar 2012, 6:24 AM
However note that you won't have access to getters and setters in init. 90% of the "initialization code" should be placed in the launch function of your controllers

metas
18 Mar 2012, 6:23 PM
Thanks Phil.Strong

"onLaunch()" in controllers like below 'MonitoringController' will not be fired.



if (selections && selections.length) {
var monitorCtrl = this.getController('MonitoringController'),
tab = Ext.widget(
'monitoringTab',
{closable: true, title: 'Monitoring - ' + selections[0].data.factory}
);
monitorCtrl.init();
this.getTabPanel().setActiveTab(this.getTabPanel().add(tab));
}

Getter for ref and store works in init().

Phil.Strong
19 Mar 2012, 8:31 PM
what works and doesn't work depends on version of ST 2 your using. The latest has a launch function (not onLaunch) and ... ref getters and setters aren't ready in init


launch: function() {

}

Phil.Strong
20 Mar 2012, 6:12 AM
ExtJS does allow for you to use init function along with controller reference getters/setters. Just to be clear.

Also onLaunch is the correct "launch" function and needs to be added as a basicFunction
fn: 'onLaunch'

metas
21 Mar 2012, 6:02 PM
Hi Pil Strong,

launch() in a controller could not be fired automatically when the controller is loaded in this way:


AnotherController.getController("TheController");


The way to fire launch() is to invoke it directly like below.


AnotherController.getController("TheController").launch();

Is it right?
As my understanding, your point is launch() should be more safe than init() because getter and setter are prepared in launch() but maybe not in init().

Thanks,
Metas

Phil.Strong
22 Mar 2012, 10:11 AM
You shouldn't need to call launch. Simply include the controller name in your Ext.Application controllers property like so:



Ext.application({
name: 'MyApp',

controllers: [
'MyController'
],

launch: function() {

}
});


where controller is:
MyApp.controller.MyController

dhana@urjita.co.in
27 Aug 2013, 11:59 PM
Hi
I am using Sencha Architect Version: 2.2.2 Build: 991,
and I am trying change the Startup application in the Launch Function and not allowed
I also have created (added) lauch function which shows empty initially and when code is added get appended with existing code

Any one found this and any resolution for this problem

Thanks
Dhana

aconran
3 Sep 2013, 8:40 AM
I also have created (added) lauch function which shows empty initially and when code is added get appended with existing code

Any one found this and any resolution for this problem


This is how it works. If you don't want architect to create the initial view and want to create your own launch code without any help from architect; right click on your initial view and say unmark as initial view.

Whatever is in your launch fn will be what is run with no additions.