I am trying to get the value for the selected child of the parent node which are not save using push id but name instead.
My firebase database : https://imgur.com/a/Lnqc80x
My current JS code:
var rootRef = firebase.database().ref('Admin').child('AssignCarTowing');
rootRef.on("child_added", function (snapshot) {
snapshot.forEach(function (snap) {
//console.log(snapshot.key);
//console.log(snap.key);
var status = snap.child("Status").val();
var name = snap.child("Name").val();
var cnum = snap.child("CarNumber").val();
var cmodel = snap.child("CarModel").val();
var hp = snap.child("ContactNo").val();
var brkloc = snap.child("BreakdownLocation").val();
var dandt = snap.child("TowingDateandTime").val();
var peric = snap.child("PersonInCharge").val();
$("#towreqlist").append("<tr><td>" + status + "</td><td>" + name + "</td><td>" + cmodel +
"</td><td>" + cnum + "</td><td>" + dandt +
"</td><td>" + hp + "</td><td>" + brkloc + "</td><td>" + peric + "</td><td><button onclick='done(\"" + snapshot.key + "\", \"" + snap.key + "\")' class='btn btn-success btn-sm'>Done</button>");
});
});
Solved by adding another ref on the node in my code
var rootRef = firebase.database().ref('Admin/Person In Charge/Towing/' + auth.currentUser.uid);
rootRef.once('value', function (snap) {
firebase.database().ref('Admin').child('AssignCarTowing').child(snap.child("Name").val()).on("child_added", function (snapshot) {
snapshot.forEach(function (snap) {
//console.log(snapshot.key);
//console.log(snap.key);
//var status = snap.child("Status").val();
var name = snap.child("CustName").val();
var cnum = snap.child("CustCarNumber").val();
var cmodel = snap.child("CustCarModel").val();
var hp = snap.child("CustContactNo").val();
var brkloc = snap.child("CustLocation").val();
var dandt = snap.child("CustBDTD").val();
//var peric = snap.child("PersonInCharge").val();
$("#towreqlist").append("<tr><td>" + name + "</td><td>" + cmodel +
"</td><td>" + cnum + "</td><td>" + dandt +
"</td><td>" + hp + "</td><td>" + brkloc + "</td><td><button onclick='done(\"" + snapshot.key + "\", \"" + snap.key + "\")' class='btn btn-success btn-sm'>Done</button>");
});
});
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.