我有一个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;
}
Run Code Online (Sandbox Code Playgroud)
虽然调试功能没有退出循环,即使tree.text(currNode) === ancestor是真的.是Jquery .each导致它.请帮我.
从jQuery文档:
我们可以通过使回调函数返回false来在特定迭代中中断$ .each()循环.返回非false与for循环中的continue语句相同; 它将立即跳到下一次迭代.
您没有返回false,因此循环将继续.
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |