Please help, I wanted to ask, is it possible to use if/else on firebase's realtime results, which is enter image description here Previously I've tried it and it works if the result of both "waktu" is same, == recent. but what I want is if one of the values "waktu" == recent, then "Hasil" = 0, if both of "time" nothing is equal to "Recent", then the value "Hasil" = 0.
if ("Recent" == (one of) "waktu") {
Hasil : "1";
} else {
Hasil : "0";
}
This is my code before, which value "Result" = 1, if both "waktu" values == recent. but i want if one value of "waktu" == Recent.
var recent = "";
var root = firebase.database().ref();
root.child("Time").on('value', (snapshot) => {
recent = snapshot.val().Recent;
});
root.child("jadwal-pakan").on('value', (snapshot) => {
snapshot.forEach(jadwal_waktu => {
if (jadwal_waktu.child("waktu").val() == recent) {
root.update({
Keadaan: {
Hasil: 1
}
});
} else {
root.update({
Keadaan: {
Hasil: 0
}
});
}
})
})Thank you :)
Aucun commentaire:
Enregistrer un commentaire