PDA

View Full Version : Move a search function from version 3 to version 4



noamway
7 Jan 2013, 7:57 PM
Hi,

I try without any success to migrate this function from version 3 to 4:

//********************** Search For - FOLDERS - *************************************
var hiddenPkgs = [];
var markCount = [];

// filter the kb tree for hits
function filterTree(e){
var text = e.target.value;
Ext.each(hiddenPkgs, function(n){
n.ui.show();
});

markCount = [];
hiddenPkgs = [];

if( text.trim().length > 0 ){
Ext.getCmp('treeFolderList').expandAll();

var re = new RegExp( Ext.escapeRe(text), 'i');
Ext.getCmp('treeFolderList').root.cascade( function( n ){
if( re.test(n.text) )
markToRoot( n, Ext.getCmp('treeFolderList').root );
});

// hide empty packages that weren't filtered
Ext.getCmp('treeFolderList').root.cascade(function(n){
if( ( !markCount[n.id] || markCount[n.id] == 0 ) && n != Ext.getCmp('treeFolderList').root ){
n.ui.hide();
hiddenPkgs.push(n);
}
});
}
}

function markToRoot( n, root ){

if( markCount[n.id] )
return;

markCount[n.id] = 1;

if( n.parentNode != null )
markToRoot( n.parentNode, root );
}
//********************** Search For - FOLDERS - *************************************

I really like to know what is the easy way to do that or maybe someone can make us an example here. Now we're getting error here: root.cascade and we don't find how to do that in version 4.

Thanks for the help,
Noam

friend
8 Jan 2013, 5:04 AM
Try this instead:



Ext.getCmp('treeFolderList').getRoot().cascade( function( n ){
if( re.test(n.text) )
markToRoot( n, Ext.getCmp('treeFolderList').getRoot() );
});


I'd also evaluate the return object from Ext.getCmp() to ensure you're actually getting a reference to the Tree.