0
我讀了一個meme的例子,但它似乎沒有更新,只是創建新的對象!我想要的是如何使用Parse雲js保存我的模型?
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");
}
);
我認爲上面的代碼可以工作 - 但事實並非如此。當它發現一個對象時,它拒絕保存,愚蠢地告訴我,我的對象沒有「保存」方法。
你是如何獲得最新解析雲SDK的版本? – bharal