控制不成功阻止parse.com

时间:2016-04-01 07:23:42

标签: javascript asynchronous parse-platform cloud-code

在下面的代码中,控件不会在bookinQuery成功块上进行。如何在Parse.com中使用find的嵌套?有人可以帮忙吗?感谢。

Parse.Cloud.define( “checkAvailibilityOfRooms”,功能(请求,响应)     {

var bookdate    = request.params.bookdate;
var reqfromtime = request.params.reqfromtime;
var reqtotime   = request.params.reqtotime;


var intervals = 48;  //Total intervals in a day for Booking 
var _in, _out, flag=true;

var room_list = []; 

var RoomObj      = Parse.Object.extend("Room");
var roomQuery    = new Parse.Query(RoomObj); 

roomQuery.find({

    success:function(results){

        for(var i=0 ; i<results.length;i++){

            room_list.push(results[i].get('room_mac_id'));
        }


         console.log(room_list[1]);

          var BookObj      = Parse.Object.extend("Booking");
          var bookingQuery = new Parse.Query(BookObj);

          for(var j=0 ; j<room_list.length;j++){

              console.log("Inside j loop");

                bookingQuery.equalTo("book_date",bookdate);
                bookingQuery.equalTo("room_mac_id",room_list[j]);
                bookingQuery.ascending("book_fromtime");

                bookingQuery.find({

                     success:function(results){

                                console.log("Inside second successs");

                                 var map = [];

                                 for(var i=0;i<intervals;i++){
                                     map.push({index: i, flag: true});
                                 }

                                 console.log(map[0]);
                                 console.log(results[0].get('book_fromtime'));


                                 for(var i=0;i<results.length;i++){
                                     _in = Math.ceil(results[i].get('book_fromtime') * 2);
                                     _out = Math.ceil(results[i].get('book_totime') * 2) - 1;


                                     for(var j=_in;j<=_out;j++){
                                         map[j].flag = false;
                                     }
                                 }


                                 _in = Math.ceil(reqfromtime * 2);
                                 _out = Math.ceil(reqtotime * 2) - 1;

                                 for(var i=_in;i<=_out;i++){

                                     if(!map[i].flag){
                                         flag=false;
                                         break;
                                     }
                                 }

                                 console.log("Status of booking");
                                 console.log(flag);

                     },

                    error:function(error){


                    }

                });//bookingQuery find block



     }



           response.success("Exclude rooms inside");
    },//success block

    error:function(error){

        response.success(error.code + error.message);
 }



}) ;

});

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我解决了它使用了不同的查询语法,我不知道它是怎么发生的,但改变这种语法是我在自己的解析服务器上唯一有用的东西......

Parse.Cloud.afterSave('Comment', function(request, response) {
   var postID = request.object.get("post_id").id;
   console.log("PostID: " + postID);
   var query = new Parse.Query('Post');
   query.equalTo("objectId", postID);
   query.first({ useMasterKey: true }).then((result) => {
      console.log('query succeeded', result);
      result.increment("commentCount"); 
      result.save();
      response.success();
   }, (error) => {
      console.log('query failed', error);
      response.error(error);
   });
});