How to read data from Realtime database firebase and show data of particular node

Viewed 25

I am trying to read data from Realtime database firebase, first it will read data of the given mobile number and then it will check whether this data is present in database or not, if it is present then it will show data on web page, i.e. machineID and its respective nickname and I only want to show nickname in web page but when we click on that nickname it will read data of the respective machineID.

here is my code:

ref.orderByKey().equalTo(phone_no).on('value', (snapshot) => {
  if (snapshot.exists()) {
    
    var mc_ref = app.database().ref('/mobile/' + phone_no);
    mc_ref.on('value', (snapshot) => {
      //console.log(snapshot.val());
      snapshot.forEach((data) => {
      //console.log(data.val());
      var mac = data.val()
      let www = app.database().ref('/All_Chassis/' + mac  )
     www.on('value',(snapshot)=>{
     let nickname=snapshot.val().NickName
      console.log(nickname)
         $("#dd .dropdown-menu")
            .append('<li><a class="dropdown-item"  target="blank" href="machine_status.html" >' +nickname +"-"+ mac+  '</a></li>');
          $(" .dropdown-container")
            .append('<a class="dropdown-item" href="machine_details.html" >'  +nickname +"-"+ mac+  '</a>');
            $("#dd .dropdown-menu")            
       
        console.log(data.val());
        
     })
        
      });
    })
  }
})


var dropdown_menu = document.getElementById('dropdown');
var selected = dropdown_menu.addEventListener('click', function (e) {

    var machineid = e.target.innerText
 });

0 Answers
Related