I wanted to add a custom object as treenode in a tree panel.
It will be used as
var complex_object = {....}
myTree.getRootNode().appendChild(new MyNode(complex_object));
To implement such feature I found Ext.data.NodeInterface whcih provides a common interface to tree nodes. So I tried to extend it. Here is how its done.
var MYNS = {
TreeNode: new Ext.Class({
protocol : "",
displayName : "",
extend: 'Ext.data.NodeInterface',
constructor : function(line) {
this.protocol = get_protocol(line);
this.displayName = get_display_name(line);
var configObj = {
id : this.protocol + "-" + this.displayName,
text : this.displayName,
leaf : true,
iconCls : protocol+"-user"
};
this.callParent([configObj]);
}
})
}
As it turns out this does not create any extended class of Ext.data.NodeInterface. It however creates object bud has not function from its parent.
var a = new MYNS.TreeNode(...);
a.appendChild(); // throws error
Am I do it wrong? How do Correctly do it?
Ext.data.NodeInterfaceis a ‘factory’ for decorating the prototype ofExt.data.Modelclasses with properties/functions required.This is how you would use it:
The central method is
Ext.data.NodeInterface#decorate– see the docs – which facilitates#getPrototypeBodyinternally. These are both static methods. You could overridegetPrototypeBodyto manipulate the class definition.For other Ext classes to pick up the changes you would rather have to override
Ext.data.NodeInterfaceinstead of extending it.However, another approach is to add the required functionality by extending
Ext.data.Model– this might actually be the more straight-forward approach to your requirement.