我有一个 JavaScript 函数:
function nodeExists(text, ancestor, tree, generationCount) {
tree.findByText(text).each(function (index, element) {
var gen = generationCount;
var currNode = element;
while (gen !== 1) { // 1: node itself
currNode = tree.parent(currNode);
gen--;
}
if (tree.text(currNode) === ancestor)
return currNode; // Even if condition is met, control continues looping
})
return null;
//return ($.inArray(ancestor, gArr) !== -1) ? true : false;
}
虽然调试功能不会退出循环,即使tree.text(currNode) === ancestor
是真的。是 Jquery .each 造成的。请帮我。