Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解析File.save()异常行为_Javascript_Parse Platform - Fatal编程技术网

Javascript 解析File.save()异常行为

Javascript 解析File.save()异常行为,javascript,parse-platform,Javascript,Parse Platform,我使用以下两种方式将图片上传到parse.com。第一种使用承诺的方法有效,但另一种不行。我是否遗漏了一些非常基本的东西 方法1: var parseFile = new Parse.File(name, file); parseFile.save().then(function (){ console.log('Picture has been successfully saved.'); callback(pictype, parseFile); }, function (err

我使用以下两种方式将图片上传到parse.com。第一种使用承诺的方法有效,但另一种不行。我是否遗漏了一些非常基本的东西

方法1:

var parseFile = new Parse.File(name, file);
parseFile.save().then(function (){
   console.log('Picture has been successfully saved.');
   callback(pictype, parseFile);
}, function (error){
   console.log('Picture cannot be saved.', error.toString());
});
方法2:

var parseFile = new Parse.File(name, file);
parseFile.save(null, {
  success: function () {
    console.log('Picture has been successfully saved.');
    callback(pictype, parseFile);
  },
  error: function (error) {
    console.log('Picture cannot be saved.', error.toString());
  }
});

这取决于Parse.File上的save方法是如何实现的。它显然返回了一个承诺,因为代码可以工作……它可能不支持success和error语法。你的代码不会失败,但它就是不工作


编辑:查看文档,您需要指定options对象(包含success和error方法)作为第一个参数。这就是您现在指定null的地方。

代码没有失败,但不起作用,这是正确的。对我来说,这似乎是一个bug,因为文档表明两者都应该很好地工作。但您指定null作为第一个参数,而不是options对象……这与parse版本1.11.1中的情况相同。第一个参数为null时,将在保存Parse.File类时卡住,而正常对象保存则可以