PDA

View Full Version : [SOLVED] 'add' event selectively for REALLY NEW child items?



k0smita
27 May 2010, 7:33 AM
In Window component, how can I invoke an event handler ONLY for those 'add' events that are raised after initial render?

I have a window with vbox layout and three panels in it. I then want to optionally insert a new panel using a button.

In the same time I want to resize the window to accommodate the new panel handling the 'add' event:


'add' : function (container, panel, index) {
this.setSize(this.getWidth(), this.getHeight() + panel.height);
},
This would not work though, because 'add' event is raised also when the first three panels are added (and I would get 'this.getResizeEl() is undefined' error).

CrazyEnigma
27 May 2010, 9:34 AM
What is "this" referring to? You may want to set the scope.

Or, the panel has not been rendered or instantiated that you can't use "this".

Maybe create the object, then use the object's on() method to create the add listener.

Condor
27 May 2010, 10:05 AM
add: {
fn: function(){...},
buffer: 10
}

Condor
27 May 2010, 10:05 AM
add: {
fn: function(){...},
buffer: 10
}

k0smita
27 May 2010, 11:22 PM
Thanks. I used the on() solution. In this way the event handler is not invoked for the panels added on initial render, exactly what I want. In fact ultimately I use the following


'afterrender': function(){
this.on('add', function(container, panel, index){
this.setSize(this.getWidth(), this.getHeight() + panel.height);
})
},

k0smita
27 May 2010, 11:31 PM
And how do I mark posts as SOLVED/CLOSED??

CrazyEnigma
28 May 2010, 5:02 AM
Go to the original post, edit post, go advanced, edit the title