-
-
Save ctmcquilkin/6722983 to your computer and use it in GitHub Desktop.
This file contains 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 pushSomething(ref) { | |
// Let's push something. push() returns a reference that you can hold onto! | |
var justPushed = ref.push({test: "push"}); | |
// We return a reference, but you can also return the name of the newly | |
// created object with .name(). | |
return justPushed; | |
} | |
function removeItem(ref) { | |
// Now we can get back to that item we just pushed via .child(). | |
ref.remove(function(error) { | |
alert(error ? "Uh oh!" : "Success!"); | |
}); | |
} | |
function go() { | |
var testRef = new Firebase("https://example.firebaseIO.com/"); | |
var newRef = pushSomething(testRef); | |
// Later... should popup an alert that says "null" (No Error). | |
removeItem(newRef); | |
} | |
/* for testing: */ | |
var name = 'me'; | |
var text = 'something'; | |
var nameRef = new Firebase('https://examplefirebase.firebaseio.com/RemoveTest'); | |
nameRef.child('test').set('anothertest'); // writing data as list (adds node directly under root) | |
nameRef.child('test').push('moretesting'); // using child instead of set (generated unique child name) (adds "moretesting" to uniquely named child node of test child node of root) | |
nameRef.push({name: name, text: text}); // automates generation of unique child names (adds uniquely named node under root with two child nodes "me" and "something") | |
nameRef.set({name: name, text: text}); // object (overwrote all child nodes of root, adds "me" and "something") | |
nameRef.update({name: name, text: text}); // writing multiple children without overwriting other data | |
$('#remove').on('click', function(){ | |
console.log('button clicked'); | |
event.preventDefault(); | |
nameRef.child('test').remove(); // this removes the parent of test (RemoveTest) | |
nameRef.child('name').remove(); // this removes "name:'me'" from root (RemoveTest) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment