I set a bookmarks and favorites page of movies to a firebase at a movie profile page. Now I am trying to grab the information from only the ones that are bookmarked, grab the information (movieIds, titles, etc., and post that onto my html page. For some reason I cannot read in the information, my console.log shows me that the array is correct and has all the information I need, however I can't access it on the html page for some reason. This is the bookmarks.js file
export default class BookmarksRoute extends Route {
async model(params) {
var user = firebase.auth().currentUser;
//check if user is logged in
if (user) {
//first check if movie has been saved before
firebase
.database()
.ref("users/" + user.uid + "/savedMovies/")
.once("value", (snapshot) => {
if (snapshot.exists()) {
//snapshot is returning the json for this particular movie saved by user id and putting it in userData
const userData = snapshot.val();
console.log("exists........", userData);
var returnArr = [];
snapshot.forEach(function (childSnapshot) {
var item = childSnapshot.val();
item.key = childSnapshot.key;
returnArr.push(item);
});
console.log("test", returnArr);
console.log("Bookmarked: ", returnArr[0].isBookmarked);
return returnArr;
}
});
}
}
}
This is the HTML file
<header class="bookmarks-header">
<h1>BookMarks</h1>
</header>
<main class="bookmark-frame">
<div class="ui four column grid">
<div id="text">
<h1></h1>
<h2></h2>
</div>
</div>
</main>
Examples of what prints on my console.log is
0: {adult: false, isBookmarked: true, isFavorited: false, movieID: 41586, poster_path: "/1ZsF9u6bBp46mMXTOpSAqowlZW4.jpg", …}
1: {isBookmarked: false, isFavorited: true, movieID: 337401, poster_path: "/aKx1ARwG55zZ0GpRvU2WrGrCG9o.jpg", release_date: "2020-09-04", …}
2: {isBookmarked: true, isFavorited: false, movieID: 497358, poster_path: "/kQp149wW9XN7lEH5B3xkKpkzYGT.jpg", release_date: "1969-12-25", …}
3: {isBookmarked: false, isFavorited: true, movieID: 577922, poster_path: "/k68nPLbIST6NP96JmTxmZijEvCA.jpg", release_date: "2020-08-22", …}
4: {isBookmarked: false, isFavorited: true, movieID: 590706, poster_path: "/eLT8Cu357VOwBVTitkmlDEg32Fs.jpg", release_date: "2020-11-20", …}
5: {isBookmarked: true, isFavorited: false, movieID: 671583, poster_path: "/xfYMQNApIIh8KhpNVtG1XRz0ZAp.jpg", release_date: "2020-07-31", …}
6: {isBookmarked: true, isFavorited: false, movieID: 729648, poster_path: "/6OeGqp18oZucUGziMIRNhLouZ75.jpg", release_date: "2020-11-02", …}
[]: (...)
firstObject: (...)
hasArrayObservers: (...)
lastObject: (...)
length: 7
__proto__: Array(0)
Export of my JSON file looks like:
{
"CfWjFzxOWBfFbfc80NFmktwFJye2" : {
"savedMovies" : {
"454433" : {
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 454433,
"poster_path" : "/awcPLFFYjufRXd2oAAP6ZIXF9vM.jpg",
"release_date" : "2020-08-14",
"title" : "Magic Camp",
"vote_average" : 7
},
"524047" : {
"isBookmarked" : false,
"isFavorited" : true,
"movieID" : 524047,
"poster_path" : "/bNo2mcvSwIvnx8K6y1euAc1TLVq.jpg",
"release_date" : "2020-07-29",
"title" : "Greenland",
"vote_average" : 7.2
},
"524087" : {
"isBookmarked" : false,
"isFavorited" : true,
"movieID" : 524087,
"poster_path" : "/3rRUp4WZdvt4LfdXIWL0qmFv9UI.jpg",
"release_date" : "2018-11-02",
"title" : "Dear Ex",
"vote_average" : 7.4
},
"590706" : {
"isBookmarked" : true,
"isFavorited" : true,
"movieID" : 590706,
"poster_path" : "/eLT8Cu357VOwBVTitkmlDEg32Fs.jpg",
"release_date" : "2020-11-20",
"title" : "Jiu Jitsu",
"vote_average" : 5.7
},
"602211" : {
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 602211,
"poster_path" : "/4n8QNNdk4BOX9Dslfbz5Dy6j1HK.jpg",
"release_date" : "2020-11-13",
"title" : "Fatman",
"vote_average" : 6.1
},
"654028" : {
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 654028,
"poster_path" : "/6sG0kbEvAi3RRLcGGU5h8l3qAPa.jpg",
"release_date" : "2020-11-18",
"title" : "The Christmas Chronicles: Part Two",
"vote_average" : 7.1
},
"724989" : {
"isBookmarked" : true,
"isFavorited" : true,
"movieID" : 724989,
"poster_path" : "/ugZW8ocsrfgI95pnQ7wrmKDxIe.jpg",
"release_date" : "2020-10-23",
"title" : "Hard Kill",
"vote_average" : 5
},
"726208" : {
"isBookmarked" : false,
"isFavorited" : true,
"movieID" : 726208,
"poster_path" : "/ffdPUteSePSqJEhKJKwgSIWumC2.jpg",
"release_date" : "2020-07-24",
"title" : "Don't Listen",
"vote_average" : 6.7
}
}
},
"uY5GV5VCMbPufW4eVQChh61sbOC2" : {
"savedMovies" : {
"41586" : {
"adult" : false,
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 41586,
"poster_path" : "/1ZsF9u6bBp46mMXTOpSAqowlZW4.jpg",
"release_date" : "1999-12-07",
"title" : "K-911",
"vote_average" : 5.5
},
"337401" : {
"isBookmarked" : false,
"isFavorited" : true,
"movieID" : 337401,
"poster_path" : "/aKx1ARwG55zZ0GpRvU2WrGrCG9o.jpg",
"release_date" : "2020-09-04",
"title" : "Mulan",
"vote_average" : 7.2
},
"497358" : {
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 497358,
"poster_path" : "/kQp149wW9XN7lEH5B3xkKpkzYGT.jpg",
"release_date" : "1969-12-25",
"title" : "Ave, Vita",
"vote_average" : 6.8
},
"577922" : {
"isBookmarked" : false,
"isFavorited" : true,
"movieID" : 577922,
"poster_path" : "/k68nPLbIST6NP96JmTxmZijEvCA.jpg",
"release_date" : "2020-08-22",
"title" : "Tenet",
"vote_average" : 7.4
},
"590706" : {
"isBookmarked" : false,
"isFavorited" : true,
"movieID" : 590706,
"poster_path" : "/eLT8Cu357VOwBVTitkmlDEg32Fs.jpg",
"release_date" : "2020-11-20",
"title" : "Jiu Jitsu",
"vote_average" : 5.7
},
"671583" : {
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 671583,
"poster_path" : "/xfYMQNApIIh8KhpNVtG1XRz0ZAp.jpg",
"release_date" : "2020-07-31",
"title" : "Upside-Down Magic",
"vote_average" : 7.7
},
"729648" : {
"isBookmarked" : true,
"isFavorited" : false,
"movieID" : 729648,
"poster_path" : "/6OeGqp18oZucUGziMIRNhLouZ75.jpg",
"release_date" : "2020-11-02",
"title" : "The Dalton Gang",
"vote_average" : 4.7
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire