PDA

View Full Version : Trouble writing extensions



Max Carey
8 Jun 2008, 11:46 PM
I'm trying to write a very simple extension of Ext.tree.TreeNode, but I'm having some issues configuring instances of my extension. I can apply a config property in the extension code before calling initComponent(), but nothing I do in initComponent() changes any properties, even if I use Ext.apply:


extensionObject = Ext.extend(Ext.tree.TreeNode, {
someProp: someValue, // This does set someProp

initComponent: function() {
Ext.apply(this, {
someProp: someOtherValue // This does not set someProp
});

this.someProp = someNewValue; // This does not set someProp either

myExtension.superclass.initComponent.apply(this, arguments);
}
}

When I create a new instance of my extension, I cannot set any properties by passing a config object to the constructor, e.g.


var extensionObject = new myExtension({someProp: someValue});

does not set someProp. The only way I can set properties is after creation:


var extensionObject = new myExtension();
extensionObject.someProp = someValue;

I don't know why none of these methods work because as far as I can tell they should all work equally well. Any ideas?

Max Carey
9 Jun 2008, 5:27 AM
Anybody? Seems like this should be fairly simple...all of the tuts use these methods for setting properties of extensions, don't know why they aren't working for me.

Max Carey
9 Jun 2008, 6:04 AM
Update: It seems like the initComponent() function of my extension never gets called. So the default values (before initComponent) set the properties, and never get overwritten from inside the extension. However, I still don't understand why passing a config object to a new extension instance wouldn't work.

Max Carey
9 Jun 2008, 6:25 AM
Found the problem: I was trying to extend Ext.tree.TreeNode. Because TreeNode is not a widget, it does not have an initComponent() method that it calls when it is created. So my initComponent() method was never called when I created a new instance of my extension.

Does anybody know how I can extend a TreeNode in a similar manner?

mjlecomte
9 Jun 2008, 4:31 PM
From the API DOCs http://extjs.com/deploy/dev/docs/?class=Ext.tree.TreeNode
TreeNode extends Node which extends Observable. initComponent is a template method for the Component Class so as you discovered initComponent isn't automatically called.

Search for other extensions that extend Observable perhaps? Check www.extjs.eu.