Add stop check in traverse

This commit is contained in:
Ludovic Stephan 2017-04-09 11:43:51 -03:00
parent 9ba13a81ee
commit 73fb3c419e

View file

@ -720,18 +720,21 @@ class ModelForest {
var that = this; var that = this;
function recurse(node) { function recurse(node) {
if (node.constructor.verbose_name === modelname) { if (node.constructor.verbose_name === modelname) {
callback(node); if callback(node);
return true;
} }
var children = that.get_children(node); var children = that.get_children(node);
if (children) { if (children) {
for (let child of children) for (let child of children)
recurse(child); if (recurse(child))
return true;
} }
} }
for (let root of this.roots) for (let root of this.roots)
recurse(root); if (recurse(root))
return ;
} }
/** /**
@ -743,8 +746,10 @@ class ModelForest {
var result = null; var result = null;
function callback(node) { function callback(node) {
if (node.id == id) if (node.id == id) {
result = node ; result = node ;
return true;
}
} }
this.traverse(modelname, callback); this.traverse(modelname, callback);