As I understand it, querying a ref using child_added does the following:
The child_added event fires once for every existing child and then continues to fire every time a new child is added.
I'm using child_added to query a ref which is populated with items - based on whether a user is signed in or not. For some reason, the function is called - but it doesn't get past ref.child_added - and I can't figure out what is wrong with the query as I've used it successfully before.
<!-- HTML (PLACED AT BOTTOM OF HTML DOC) -->
<script src="js/firebase.js"></script>
</body>
// firebase.js
var data = firebase.database().ref('item/');
function getItems(ref){
console.log("getItem FUNC HAS BEEN CALLED"); // LOGS TO CONSOLE
console.log("THE REF IS:" + ref); // LOGS TO CONSOLE
ref.on("child_added", function(snapshot) {
console.log("child_added was called"); // DOESN'T LOG
var artistItem = snapshot.val();
// REST OF FUNCTION
});
firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser) {
getItems(data);
console.log('getItems WAS RUN'); // LOGS TO CONSOLE
} else {
console.log("NOT LOGGED IN"); // LOGS TO CONSOLE
}
});
What is the problem here? I've tried many ways of implementing this function (in terms of placement). What am I missing.
Aucun commentaire:
Enregistrer un commentaire