Souffiane
Souffiane

Reputation: 33

Extjs - Cannot hide window

I'm using Extjs 4.2 and I got a problem.

I created an object "Window_Graph" wich extends "Window". When I try to hide this object, it makes a javascript error : "Uncaught TypeError: Cannot call method 'apply' of undefined".

There is my object :

Ext.define('PFS.view.Window_Graph', {
    extend: 'Ext.Window',
    alias: 'widget.window_graph',
    layout: 'fit',
    border: false,
    closable: true,
    header: true,
    draggable: true,
    resizable: true,
    border: false,
    tbar: [
        { xtype: 'button', action: 'modifier',       text: 'Modifier',       iconCls: 'iconAppEdit'     },
        { xtype: 'button', action: 'deplacer',       text: 'Déplacer',       iconCls: 'iconArrowOut'    },
        { xtype: 'button', action: 'redimensionner', text: 'Redimensionner', iconCls: 'iconShapeHandles'},
        { xtype: 'button', action: 'supprimer',      text: 'Supprimer',      iconCls: 'iconCross'       },
    ],
    autoShow: true,
    constrain: true
});

There is when I create my window_graph :

Ext.getCmp('page1').add({
    xtype:    'window_graph',
    id:       'graph_1',
    width:    500,
    height:   300,
    x:        10,
    y:        10
});

And next, I try to hide it like that :

Ext.getCmp('graph_1').hide();

Thanks.

Upvotes: 0

Views: 623

Answers (1)

harry
harry

Reputation: 702

Ext.getCmp is returing undefined in your case! This is what the error message is telling you.

I think I know the reason why you are getting this. The initialization process isn't finished yet. You are calling Ext.getCmp("graph_1") too early. If you want to hide the window upon creation use autoShow=false.

Alternatively you can also try this

var graphWindow = Ext.ComponentQuery.query("window_graph")[0];
debugger; //look in the console if you are getting an object back.
graphWindow.hide();

Upvotes: 1

Related Questions