Currently, I am in the process of developing Parse Cloud Code to retrieve JSON data from a third-party API. My goal is to make modifications to the data, check if it already exists, and save it if it doesn't. However, I am encountering difficulties in retaining the object after the verification process.
Here's an illustration of the issue I am facing. Upon reaching the success block, I require the original 'car' object to be able to store it in the Parse database. Sadly, the object is undefined at this point. As a newcomer to JavaScript, I acknowledge that there may be something obvious that I am overlooking.
for (var j = 0, leng = cars.length; j < leng; ++j) {
var car = cars[j];
var Car = Parse.Object.extend("Car");
var query = new Parse.Query(Car);
query.equalTo("dodge", car.model);
query.find({
success: function(results) {
if (results.length === 0) {
//save car... however, 'car' is undefined here.
}
},
error: function(error) {
console.error("Error: " + error.code + " " + error.message);
}
});
}
If anyone could steer me in the right direction, I would greatly appreciate it. Thank you!