-
22 Jun 2011 1:15 AM #1
HELP - EXTJS 4 Desktop launch a module from another one
HELP - EXTJS 4 Desktop launch a module from another one
Hi,
I'm coding an application that use the Desktop example and i'm a little lost with a thing concerning modules..And i got mad by the way :-)
I have a module that display information via a draw component and want to launch another module when clicking on this component.
Of course, i got an error... : it's stating that this.app.getDesktop() doesn't exists. in fact this.app doesn't exist all when invoking module this way from another module
So i'm lost with classes here
my event code :
the code that cause the error on the module:PHP Code:drawComponent.on({
'click': function() {
console.log('on mouseClick Event');
rectangles = this.surface.getGroup('rectangles');
var ext_win = new MyDesktop.GridWindow();
var t2 = ext_win.createWindow()
...
PHP Code:Ext.define('MyDesktop.GridWindow', {
extend: 'Ext.ux.desktop.Module',
requires: [
'Ext.data.ArrayStore',
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer'
],
id:'grid-win',
init : function(){
this.launcher = {
text: 'Grid Window',
iconCls:'icon-grid',
handler : this.createWindow,
scope: this
};
},
createWindow : function(){
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-win');
if(!win){
win = desktop.createWindow({
...
-
22 Jun 2011 4:39 AM #2
some news...
in the target module createwindow() function, if i replace:
with:PHP Code:var desktop = this.app.getDesktop();
it works, but i still dont understand how to do this a cleaner way (and i am not a web developper so i'm a bit limited ;-))PHP Code:var desktop = myDesktopApp.desktop.app.getDesktop();
-
22 Jun 2011 12:16 PM #3
In javascript, it's all about scope. There are a lot of very interesting (infuriating) effects that can happen due to an unexpected 'scope' in the executing code. At the class level of the module 'app' may be defined, but if a button is clicked, the scope is set to the button itself, not the containing class instance. There are some helper configuration settings with most of the ExtJS components to force a scope but I've always found it easier to make sure that each component/store/etc... instance is easily searchable and get a reference that way.
Read up on scope and get a good understanding of how it's applied within ExtJS. It's worth the effort. You'll have a lot less headaches when you do.
Randy


Reply With Quote