package/ui/phpvirtualbox/js/utils.js
/**
 * Traverse a tree and return matching nodes.
 * @param {Object} tree - tree to traverse
 * @param {String} prop - node property to match
 * @param {Mixed} val - value that node property must match
 * @param {Boolean} all - return all results rather than stopping at first matching node (optional)
 * @param {String} children - search node children in property named by this argument (optional)
 * @return all matched nodes | first matched node | null
 */
Traverse a tree and return matching nodes.
Traverse a tree and return matching nodes .
function vboxTraverse(tree,prop,val,all,children) {
	var leafs = new Array();
	for(var a in tree) {
		if(tree[a][prop] == val) {
			if(!all) return tree[a];
			leafs[leafs.length] = tree[a];
		}
		if(children && tree[a][children] && tree[a][children].length) {
			var c = vboxTraverse(tree[a][children],prop,val,all,children);
			if(!all && c) { return c; }
			else if(c && c.length) {
				leafs = leafs.concat(c);
			}
		}
	}
	return (all ? leafs : null);
}
function vboxTraverse ( tree , prop , val , all , children ) { var leafs = new Array ( ) ; for ( var a in tree ) { if ( tree [ a ] [ prop ] == val ) { if ( ! all ) return tree [ a ] ; leafs [ leafs . length ] = tree [ a ] ; } if ( children && tree [ a ] [ children ] && tree [ a ] [ children ] . length ) { var c = vboxTraverse ( tree [ a ] [ children ] , prop , val , all , children ) ; if ( ! all && c ) { return c ; } else if ( c && c . length ) { leafs = leafs . concat ( c ) ; } } } return ( all ? leafs : null ) ; }
Traverse a tree and return matching nodes.
Traverse a tree and return matching nodes .