Javascript 如何使用Parse cloud js保存我的模型?
我读过meme示例,但它似乎没有更新,只是创建了新对象!我想要的是Javascript 如何使用Parse cloud js保存我的模型?,javascript,backbone.js,parse-platform,Javascript,Backbone.js,Parse Platform,我读过meme示例,但它似乎没有更新,只是创建了新对象!我想要的是 a. find some given db table b. update some fields in the db table c. save the db table back to the database 给定这段代码,我可以实际更新对象所缺少的部分是什么 query.find( function(results){ if (results.length > 0){
a. find some given db table
b. update some fields in the db table
c. save the db table back to the database
给定这段代码,我可以实际更新对象所缺少的部分是什么
query.find(
function(results){
if (results.length > 0){
return results[0];
} else {
//no object found, so i want to make an object... do i do that here?
return null;
}
},
function(error){
response.error("ServerDown");
console.error("ServerDown - getModuleIfAny URGENT. Failed to retrieve from the ModuleResults table" + +error.code+ " " +error.message);
}
).then(
function(obj){
var module;
if (obj != null){
console.log("old");
module = obj;
module.moduleId = 10; //let's just say this is where i update the field
//is this how i'd update some column in the database?
} else {
console.log("new");
var theModuleClass = Parse.Object.extend("ModuleResults");
module= new theModuleClass();
}
module.save().then(
function(){
response.success("YAY");
},
function(error) {
response.error('Failed saving: '+error.code);
}
);
},
function(error){
console.log("sod");
}
);
我原以为上面的代码会起作用,但事实并非如此。当它找到一个对象时,它拒绝保存,愚蠢地告诉我我的对象没有“保存”方法。首先,我会仔细检查您在云代码中使用的javascript sdk的版本。确保它是最新的,例如1.2.8。版本设置在云代码目录下的config/global.json文件中 假设您是最新的,我会尝试通过使用多个链接链接承诺来修改您的代码,如下所示:
query.find().then(function(results){
if (results.length > 0){
return results[0];
} else {
//no object found, so i want to make an object... do i do that here?
return null;
}
},
function(error){
response.error("ServerDown");
console.error("ServerDown - getModuleIfAny URGENT. Failed to retrieve from the ModuleResults table" + +error.code+ " " +error.message);
}).then(function(obj){
var module;
if (obj != null){
console.log("old");
module = obj;
module.moduleId = 10; //let's just say this is where i update the field
//is this how i'd update some column in the database?
} else {
console.log("new");
var theModuleClass = Parse.Object.extend("ModuleResults");
module= new theModuleClass();
}
module.save();
}).then(function(result) {
// the object was saved.
},
function(error) {
// there was some error.
});
我认为这应该行得通。祝你好运。干杯 您是如何获得最新parse cloud sdk的版本的?