I am currently working with a firebase database that contains multiple collections. Using the code provided, I have managed to successfully retrieve an array that consists of all attractions with an area_id that matches the area_id of e.target.
However, there seems to be a problem in my code where the attraction.id (which is a different key than area_id) is being changed to the object's index in the array. For example, id 1 is becoming 0, id 2 is becoming 1, and so on...
Initially, I suspected that this issue was occurring in the Object.keys method, so I added a console log right before it, only to find that the change had already taken place. Therefore, I am almost certain that the problem lies within the query. Any assistance on this matter would be greatly appreciated.
const getAttractionsByArea = (area_id) => {
let attractions = [];
return new Promise((resolve, reject) => {
$.ajax(`https://theme-park.firebaseio.com/attractions.json?orderBy="area_id"&equalTo=${area_id}`)
.then((results) => {
Object.keys(results).forEach((result) => {
results[result].id = result;
attractions.push(results[result]);
});
resolve(attractions);
}).catch((err) => {
reject(err);
});
});
};