crp_spaeth
20 Jun 2009, 1:00 AM
Hi there,
My backendsystem doesn't sent the Data in the way a Standard Ext.tree.TreeNode consumes it, so I needed a kind of mapping to map attributes comming from the Server to the correct attributes of the treenode.
I found a way to do that by extending Ext.tree.AsyncTreeNode the following way:
Ext.tree.MappedTreeNode = function(attributes){
// mapping
if(typeof attributes == "string"){
attributes = {text: attributes};
} else {
attributes = this.mapAttributes(attributes);
attributes = attributes || {};
}
Ext.tree.MappedTreeNode.superclass.constructor.call(this, attributes);
}
Ext.extend(Ext.tree.MappedTreeNode, Ext.tree.AsyncTreeNode, {
/**
* Override this function to map the Serverresponse to your actual Treeode
* @param {Object} attr attributes as respond by the Server
* @return {Object} attributes as they are consumable by the TreeNode
*/
mapAttributes: function(attr){
return attr;
}//,
});
This makes it realy easy to implement your own TreeNodes with its own mapping
For Example you can implement a node that consumes the following response:
{EXTID:'nodeid1', name: 'a text', text:'another Text', nodeType: 'TestNode'}
All you need to do is Create your own NodeType in the following way:
MyAPP.TestNode = Ext.extend(Ext.tree.MappedTreeNode, {
// override the mapAttributes function
mapAttributes: function(unMappedAttr) {
var mappedAttr = {};
mappedAttr.id = unMappedAttr.EXTID;
mappedAttr.text = name + ' ' + text;
return mappedAttr;
}
});
// register the nodeType
if(!Ext.tree.TreePanel.nodeTypes) {
Ext.tree.TreePanel.nodeTypes = {};
}
Ext.tree.TreePanel.nodeTypes["TestNode"] = MyAPP.TestNode;
I think something like that would be really helpful in the standard?
What do you think
My backendsystem doesn't sent the Data in the way a Standard Ext.tree.TreeNode consumes it, so I needed a kind of mapping to map attributes comming from the Server to the correct attributes of the treenode.
I found a way to do that by extending Ext.tree.AsyncTreeNode the following way:
Ext.tree.MappedTreeNode = function(attributes){
// mapping
if(typeof attributes == "string"){
attributes = {text: attributes};
} else {
attributes = this.mapAttributes(attributes);
attributes = attributes || {};
}
Ext.tree.MappedTreeNode.superclass.constructor.call(this, attributes);
}
Ext.extend(Ext.tree.MappedTreeNode, Ext.tree.AsyncTreeNode, {
/**
* Override this function to map the Serverresponse to your actual Treeode
* @param {Object} attr attributes as respond by the Server
* @return {Object} attributes as they are consumable by the TreeNode
*/
mapAttributes: function(attr){
return attr;
}//,
});
This makes it realy easy to implement your own TreeNodes with its own mapping
For Example you can implement a node that consumes the following response:
{EXTID:'nodeid1', name: 'a text', text:'another Text', nodeType: 'TestNode'}
All you need to do is Create your own NodeType in the following way:
MyAPP.TestNode = Ext.extend(Ext.tree.MappedTreeNode, {
// override the mapAttributes function
mapAttributes: function(unMappedAttr) {
var mappedAttr = {};
mappedAttr.id = unMappedAttr.EXTID;
mappedAttr.text = name + ' ' + text;
return mappedAttr;
}
});
// register the nodeType
if(!Ext.tree.TreePanel.nodeTypes) {
Ext.tree.TreePanel.nodeTypes = {};
}
Ext.tree.TreePanel.nodeTypes["TestNode"] = MyAPP.TestNode;
I think something like that would be really helpful in the standard?
What do you think