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

   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;


噜噜哒
浏览 582回答 1
1回答

慕森王

continue的意思是跳过这轮循环,马上开始下轮循环。 在你的代码中,执行continue,那么if语句continue之后的都不执行了。 i++后执行新的一轮循环判断。若想去掉,你就反着写呗,即满足xxx条件才执行if continue下面的语句for&nbsp;(var&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;<&nbsp;aggregations.all_outdept_name.buckets.length;&nbsp;i++)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!(aggregations.all_outdept_name.buckets[i].key&nbsp;==&nbsp;'')){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;department_obj&nbsp;=&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value:&nbsp;aggregations.all_outdept_name.buckets[i].key,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label:&nbsp;aggregations.all_outdept_name.buckets[i].key,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count:&nbsp;aggregations.all_outdept_name.buckets[i].doc_count &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my_department.push(department_obj); &nbsp;&nbsp;&nbsp;&nbsp;} }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript