Javascript 解析File.save()异常行为
我使用以下两种方式将图片上传到parse.com。第一种使用承诺的方法有效,但另一种不行。我是否遗漏了一些非常基本的东西 方法1: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
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类时卡住,而正常对象保存则可以