相关疑难解决方法(0)

cursor.forEach()中的"continue"

我正在使用meteor.js和MongoDB构建一个应用程序,我有一个关于cursor.forEach()的问题.我想检查每个forEach迭代开始时的一些条件,然后跳过元素,如果我不需要对它进行操作,那么我可以节省一些时间.

这是我的代码:

// Fetch all objects in SomeElements collection
var elementsCollection = SomeElements.find();
elementsCollection.forEach(function(element){
  if (element.shouldBeProcessed == false){
    // Here I would like to continue to the next element if this one 
    // doesn't have to be processed
  }else{
    // This part should be avoided if not neccessary
    doSomeLengthyOperation();
  }
});
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用cursor.find().fetch()将光标转换为数组,然后使用常规for循环迭代元素并使用continue并正常打破但是我很感兴趣,如果在forEach中有类似的东西( ).

javascript foreach mongodb meteor

244
推荐指数
4
解决办法
18万
查看次数

标签 统计

foreach ×1

javascript ×1

meteor ×1

mongodb ×1