Last active
August 29, 2015 13:56
-
-
Save bdickason/8885665 to your computer and use it in GitHub Desktop.
Example: listen to data from firebase and
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function eventManager(evt) { | |
var movement = $('#movementInput').val(); | |
var date = Date(); | |
movementsRef.push({name: movement, created: date}); | |
event.preventDefault(); | |
$('#movementInput').val(''); // Added this to clear the value of the input field after a submit. You would probably want to add validation before this step eventually | |
} | |
movementsRef.on('child_added', function(snapshot){ | |
var movementData = snapshot.val(); | |
console.log("Movement:" + movementData.name + " Created:" + movementData.created); | |
// movementsRef.toString() - Gets the URL of your current firebase location - https://www.firebase.com/docs/javascript/firebase/tostring.html | |
// snapshot.name() - Gets the 'name' aka unique ID of your current snapshot - https://www.firebase.com/docs/javascript/datasnapshot/name.html | |
// movementData.name - You used this above to display the name of your movement | |
var object = "<li><A HREF='" + movementsRef.toString() + '/' + snapshot.name() + "'>" + movementData.name + "</a></li>"; | |
$('.movements').append(object); | |
}); | |
window.onload=function() { | |
var submit = document.getElementById("movementSubmit"); | |
submit.onclick = eventManager; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment