Reputation: 6608
I try to update a value in my Parse.com Core, but it simply does not work. I have the "objectID" of the item that i want to update
Parse.initialize("xxxx", "xxxx");
var PP = Parse.Object.extend("PP");
var PP = new PP();
var query = new Parse.Query(PP);
query.equalTo("objectId", "3Enwfu0QPQ");
query.first({
success: function (PP) {
PP.save(null, {
success: function (PP) {
PP.set("free", "100");
PP.save();
}
});
}
});
i want to set the value of "free" for object "3Enwfu0QpQ" to 100, but it does not work.
Upvotes: 0
Views: 1198
Reputation: 7670
There's several issues with your code:
1.
var PP = Parse.Object.extend("PP");
var PP = new PP();
According to your screenshot, the Class is named "P", not "PP". You are also overriding the PP object.
2.
var query = new Parse.Query(PP);
query.equalTo("objectId", "3Enwfu0QPQ");
query.first({[...]});
query
is invalide because PP is no longer the PP object. You should also use query.get instead of equalTo
.
3.
PP.save(null, {
success: function (PP) {
PP.set("free", "100");
PP.save();
}
});
You are saving an empty object then editing this same object, then you update it again.
Your code should look like this (untested).
Parse.initialize("xxxx", "xxxx");
var P = Parse.Object.extend("P");
var query = new Parse.Query(P);
query.get('3Enwfu0QPQ', { // we get the object
success: function (instance) {
instance.set("free", "100"); // We update the returned object
instance.save(); // we save it
}
});
You can also save a request by doing so:
Parse.initialize("xxxx", "xxxx");
var P = Parse.Object.extend("P");
var instance = new P();
instance.id = '3Enwfu0QPQ';
instance.set("free", "100");
instance.save();
Upvotes: 2