PDA

View Full Version : Is getCmp the only way to get parent element from listener?



_Scorpion_
30 Oct 2013, 2:38 AM
Hi! In my project I've found some strange thing and I'm not sure if it's ok or not.
I define class which extends 'Ext.tree.Panel' and have id='themesGrid'.
I have several listeners defined like:


Ext.define('mypackage.MyTree', {
extend: 'Ext.tree.Panel',
id: 'themesGrid',
...
initComponent: function () {
Ext.apply(this, {
...
viewConfig: {
listeners: { //<- Here are listeners - "beforedrop", etc.
...

And in these listeners I get parent TreePanel only using Ext.getCmp('themesGrid'), which looks "not right" for me. Can someone enlighten me and tell me if I'm wrong here?

Piruthu
30 Oct 2013, 2:49 AM
In your initComponent, create a reference var like


var me = this;

Then inside listeners, use that ref ... for eg., me.yourFunction

_Scorpion_
30 Oct 2013, 3:56 AM
Works great, thanks! I felt that something was wrong there... :)