为了账号安全,请及时绑定邮箱和手机立即绑定

想知道continue在这里起什么作用,去掉得话应该如何改写?

想知道continue在这里起什么作用,去掉得话应该如何改写?

噜噜哒 2018-09-01 20:10:01
   var my_department = [];                    for (var i = 0; i < aggregations.all_outdept_name.buckets.length; i++) {                        if (aggregations.all_outdept_name.buckets[i].key == '') continue;                        var department_obj = {                             value: aggregations.all_outdept_name.buckets[i].key,                            label: aggregations.all_outdept_name.buckets[i].key,                             count: aggregations.all_outdept_name.buckets[i].doc_count                         }                         my_department.push(department_obj);                     }                     _this.department = my_department;
查看完整描述

1 回答

?
慕森王

TA贡献1777条经验 获得超3个赞

continue的意思是跳过这轮循环,马上开始下轮循环。 在你的代码中,执行continue,那么if语句continue之后的都不执行了。 i++后执行新的一轮循环判断。

若想去掉,你就反着写呗,即满足xxx条件才执行if continue下面的语句

for (var i = 0; i < aggregations.all_outdept_name.buckets.length; i++) {    if (!(aggregations.all_outdept_name.buckets[i].key == '')){        var department_obj = {            value: aggregations.all_outdept_name.buckets[i].key,            label: aggregations.all_outdept_name.buckets[i].key,            count: aggregations.all_outdept_name.buckets[i].doc_count
        }
        my_department.push(department_obj);
    }
}


查看完整回答
反对 回复 2018-09-01
  • 1 回答
  • 0 关注
  • 559 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信