0
votes

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.

1
Can you show the code where you have your instance that you are trying to hide? - kevhender
I've edited my post... Thanks. - Souffiane
There must be something else in there causing problems, I tried the code in my next comment at this page and did not have any issues: try.sencha.com/extjs/4.2.0/docs/Ext.window.Window.1/viewer.html Do you see differences in what I have vs what you have? - kevhender
Code I tried: Ext.onReady(function () { 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',text: 'Modifier'}], autoShow: true, constrain: true }); Ext.create('Ext.panel.Panel', { id: 'myPanel', title: 'Test Panel', renderTo: Ext.getBody() }); Ext.getCmp('myPanel').add({xtype: 'window_graph', id:'myWin'}); Ext.getCmp('myWin').hide() }); - kevhender
I'm not seeing any issues either: jsfiddle.net/n3g4U/1 - zeke

1 Answers

1
votes

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();