javascript - Firebase viewing the specific child on the list. Website -


how view specific child on list on javascript.

my code:

var rootref = firebase.database().ref().child("tutee");  rootref.on("child_added", snap => {  var sno = snap.child("studentnumber").val(); var fname = snap.child("firstname").val(); var lname = snap.child("lastname").val(); var email = snap.child("email").val(); var key = snap.key; var view = snap.key; var btn = "<button key='"+ key +"' class='removeemployee mdl-button mdl-js- button mdl-button--raised mdl-js-ripple-effect mdl-button-- accent'>remove</button>"; var btnview = "<button view='"+ view +"' class='removeemployee mdl-button  mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button-- accent'>view</button>";    $("#table_body").append("<tr><td>"+sno+"</td><td>"+fname+"</td><td>  "+lname+"</td><td>" + btn + "</td><td>" + btnview + "</td></tr>");  }); /* delete */  $('#table_body').on('click', ".removeemployee", function(){ // note: using  'removeelement' class, not id var key = $(this).attr('key'); var itemtoremove = rootref.child(key); itemtoremove.remove() .then(function() { // removed firebase db console.log("remove succeeded.") alert("successfully remove."); window.location.reload(); }) .catch(function(error) { console.log("remove failed: " + error.message) });  }); // keeping separate if item removed other  means (e.g.- directly server console) ui remain in sync rootref.on('child_removed', function(snap) { var key = snap.key; $('#'+key).remove(); }); 

i want click view button, go information of child click it.

i think want retrieve data on view button's click. if , can put following code under view button's click function.

var key = $(this).attr('view'); firebase.database().ref("tutee/" + key).once("value", snap =>{               var sno = snap.val().studentnumber;               var fname = snap.val().firstname;               var lname = snap.val().lastname;               var email = snap.val().email; } 

read , retreiving data firebase.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -