[1.1rc1] getNodeById() fails after replaceChild()
(1) do a replaceChild() with the new child having the same ID as the old child
and
(2) do a getNodeById() with the id,
you will get an undefined.
This is because TreePanel keeps an ID hash. The default implementation of replaceChild inserts the new node and then removes the old node. This means that the ID gets added into the hash (while it already exists) and then deleted.
I have code to demonstrate and fix the issue.
var tree = new Ext.tree.TreePanel('tree-div', {});
var root = new Ext.tree.AsyncTreeNode( { id: 1, text: 'root' } );
tree.setRootNode( root );
var child = new Ext.tree.AsyncTreeNode( { id: 2, text: 'bla' } );
root.appendChild( child )
alert( "(1) Initial: " + tree.getNodeById( 2 ) );
root.replaceChild( new Ext.tree.AsyncTreeNode( { id: 2, text: 'xorf' } ), child );
alert( "(1) Replaced: " + tree.getNodeById( 2 ) );
Ext.tree.TreeNode.prototype.replaceChild = function( n, o ) {
var sib = null;
if (o)
{
sib = o.nextSibling;
this.removeChild( o );
}
this.insertBefore( n, sib );
}
var root = new Ext.tree.AsyncTreeNode( { id: 1, text: 'root' } );
tree.setRootNode( root );
var child = new Ext.tree.AsyncTreeNode( { id: 2, text: 'bla' } );
root.appendChild( child );
alert( "(2) Initial: " + tree.getNodeById( 2 ) );
root.replaceChild( new Ext.tree.AsyncTreeNode( { id: 2, text: 'xorf' } ), child );
alert( "(2) Replaced: " + tree.getNodeById( 2 ) );
have you tried your code with 1.1.1 final?
[edit]
on closer inspection, that's going to fail regardless...
you might want to use Ext.override instead:
Ext.override(Ext.tree.TreeNode, {
replaceChild: function( n, o ) {
var sib = null;
if (o)
{
sib = o.nextSibling;
this.removeChild( o );
}
this.insertBefore( n, sib );
}
});
then include that override in a separate overrides js file
#If you have any other info about this subject , Please add it free.# |

