Javascript 中断主循环-jstree

Javascript 中断主循环-jstree,javascript,jstree,Javascript,Jstree,我正在使用jstree库显示一棵树 在下面的代码中,我循环遍历树中的选定节点,并根据某些条件,为变量“allow_edit”指定布尔值 如果'allow\u edit=false',我想中断主循环。 我尝试使用标签和打破循环,但这似乎不起作用。我得到了未定义的标签 loop1: $j.each($j("#demo2").jstree("get_selected"), function(index, element) { var selected_node_depth = parseInt(

我正在使用jstree库显示一棵树

在下面的代码中,我循环遍历树中的选定节点,并根据某些条件,为变量“allow_edit”指定布尔值

如果
'allow\u edit=false',我想中断主循环。

我尝试使用标签和打破循环,但这似乎不起作用。我得到了未定义的标签

loop1:
$j.each($j("#demo2").jstree("get_selected"), function(index, element) {

  var selected_node_depth = parseInt($j(element).attr('node_depth'));
  var allow_edit = false;


  var array_first_filter = $j.grep(array_first, function(v) { return v[1]  != "not detected";})
  var array_second_filter = $j.grep(array_first_filter, function(v) { return v[3] > selected_node_depth;})


  if (array_second_filter.length === 0 || array_second_filter.length == null)
  {
    allow_edit = true;
  }
  else{
    alert("Confliction exists in your selected terms.");
    allow_edit = false;
    //break loop1; /** not working, getting undefined label **/
  }


}

如果
'allow\u edit=false'
,有没有关于如何中断主循环的建议?非常感谢

如果传递给
的函数返回
false
,则迭代将停止

else {
  allow_edit = false; // pointless since you're about to return ...
  return false;
}
此外,作为编程风格的说明,表单的任何构造:

if (something) {
  flag = true;
}
else {
  flag = false;
}
可以更好地写为:

flag = something;
在JavaScript中,要强制
标志
为布尔值(
true
false
),可以执行以下操作:

flag = !!(something);
这两个
(逻辑“not”)运算符强制将表达式(“某物”)作为布尔值进行计算,计算规则与该表达式作为
if
语句的测试子句时使用的规则相同