按ID删除JSSDK删除对象

时间:2014-07-07 18:11:25

标签: javascript node.js parse-platform

我正在尝试删除云代码中的对象,并且我在我的控制器中有这个功能。

<!--language:lang-js-->

exports.del = function(req, res) {
  var post = new Parse.Query(CCPost);
  var objectId = req.params.id;
  post.get(objectId, {
    success: function(myObj) {
      // The object was retrieved successfully.
      myObj.destroy({
        success: function() {
          response.success('record deleted successfully');
        },
        error: function(error) {
          response.error('record delete failed');
        }
      });
    },
    error: function(object, error) {
      // The object was not retrieved successfully.
      // error is a Parse.Error with an error code and description.
    }
  });
};

我收到以下错误。

E2014-07-07T18:05:58.186Z] v69: Ran custom endpoint with:

Input: {"method"=>"DELETE", "url"=>"/admin/post/UHvT5Ov2NO", "headers"=>{"version"=>"HTTP/1.1", "host"=>"share.cakeclub.me", "user-agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36", "content-length"=>"144", "accept"=>"*/*", "accept-encoding"=>"gzip,deflate,sdch", "accept-language"=>"es,en-US;q=0.8,en;q=0.6", "cache-control"=>"no-cache", "content-type"=>"multipart/form-data; boundary=----WebKitFormBoundaryvzJX2gV7ZoN1mh2W", "origin"=>"chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm", "x-forwarded-proto"=>"http"}}

Result: success/error was not called

我不确定我在这里做错了什么,任何帮助都会很棒。

修改

我已经编辑了我的代码。

<!--language:lang-js-->

exports.del = function(req, res) {
  var obj = new Parse.Object("CCPost"); 
  obj.id = req.params.id; 

  obj.destroy({
    success: function() {
      response.success('record deleted successfully');
    },
    error: function(error) {
      response.error('record delete failed');
    }
  });
};

这看起来不错吗?

1 个答案:

答案 0 :(得分:3)

我的最终代码块用于删除,感谢指针!

app.get('/admin/post/:id', function(req, res) {
    if (Parse.User.current()) {
        var PFObject = new Parse.Object("CCPost"); 
        PFObject.id = req.params.id; 

        PFObject.destroy({
          success: function() {
            res.redirect('/admin');
          },
          error: function(error) {
            res.send(500 ,'record delete failed -- '+ error.status);
            console.log(error);
          }
        });
    } else {
        res.redirect('/admin/login');
    }
});