解析后台作业添加多个记录导致错误

时间:2014-04-28 16:06:00

标签: javascript parse-platform

我收到了奇怪的错误。

失败:错误:无法多次调用成功/错误     在updateJobMessageAndReturn(:790:5)     at Object.success(:826:9) 这是我的代码。

Parse.Cloud.job("jobAddTags", function(request, status) {
var array=request.params.tagArray;

 for (var i = 0; i < array.length; i++) {
    query = new Parse.Query("Tags");
    query.limit(1);
    query.find({
      success: function(object) {
      if (object) {
        //update
        object.increment("count");
        object.save();
      } else {
        console.log("Add New");
        var tag = Parse.Object.extend("Tags");
        var activity = new Activity();
        tag.set("tag",request.object.get("tag"));
        tag.save();
      }//end else
    }, //end success
  error: function(error) {
    status.error("Uh oh, something went wrong." + error.code + ": " + error.message);
  }//end find
});
status.success("Done Adding Tags");

} //结束 }); //结束工作

1 个答案:

答案 0 :(得分:1)

将status.success向下移动,使其超出for循环:

      ...
      error: function(error) {
        status.error("Uh oh, something went wrong." + error.code + ": " + error.message);
      }//end find
    });

  }//end for
  status.success("Done Adding Tags");
});//end job