var a = prompt("What is your phone number");
var database = firebase.database();
var fruits = database.ref('fruits');
var data = {
name: (a),
count: (a)
}
database.ref('fruits').push(data);
fruits.push(data, finished);
function finished(error) {
if (error) {
console.log('ooops');
} else {
console.log('data saved!');
}
}
var ref = firebase.database().ref();
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (error) {
console.log("Error: " + error.code);
});
var playersRef = firebase.database().ref("fruits");
playersRef.orderByChild("name").on("child_added", function(data) {
var PD = (data.val().name);
confirm(PD)
});
由于某种原因,此代码在firebase实时数据库中产生了自己的副本。有人可以帮我吗?
答案 0 :(得分:1)
似乎您有两行连续的代码行,每行代码都推送相同的数据,从而导致重复。
database.ref('fruits').push(data);
fruits.push(data, finished);
尝试删除这些行之一