Javascript 请告诉我解析承诺的基本模式

Javascript 请告诉我解析承诺的基本模式,javascript,parse-platform,promise,parse-cloud-code,Javascript,Parse Platform,Promise,Parse Cloud Code,我很难把我的头放在我的承诺上。 我正试图保存一个可能有图像的对象。我可以保存帖子,但图像永远不会保存 这是我试图让承诺生效的尝试 var savePromise = new Parse.Promise.as(); if(request.params.imageData){ // if there is image data, save the image var image = new Parse.File(fileName, request.params.imageData);

我很难把我的头放在我的承诺上。 我正试图保存一个可能有图像的对象。我可以保存帖子,但图像永远不会保存

这是我试图让承诺生效的尝试

var savePromise = new Parse.Promise.as();

  if(request.params.imageData){ // if there is image data, save the image

    var image = new Parse.File(fileName, request.params.imageData);

   savePromise = image.save().then(function() {
    groupPost.set(constants.kBPGroupImageKey, image);
    });
 }

else{// no saved image, resolve the promise and save
    return savePromise;   
}
    groupPost.save().then(function(groupPost){

任何帮助都将不胜感激

嘿,感谢您的回复,这将保存图像,但如果没有图像,则无法正确保存。如果请求不包含图像,您能否将帖子保存在else块中?我需要访问返回的对象并将指针保存到另一个对象。如果没有“图像”,则如何创建指向它的指针?也许这个问题偏离了最初的承诺模式问题。
if(request.params.imageData){
    //create the image
    var image = new Parse.File(fileName, request.params.imageData);

    image.save()
       .then(function(savedImage) {
           //returns your savedImage if you want to use it

           groupPost.set(constants.kBPGroupImageKey, image);

           // return the promise to chain them using 'then'
           return groupPost.save(); })
       .then(function(savedGroupPost) {
           //grouppost is saved
        }, function(error) {
           // errors will bubble up here
    });
 }