我想显示从firebase检索到的数据,检索成功但只显示一个"客户端"
这里是javaScript代码:
var config = {
apiKey: "AIzaSyCHoJfq1lIph8gr4AQ0pTt2mClKzm06HlQ",
authDomain: "contactform-4376b.firebaseapp.com",
databaseURL: "https://contactform-4376b.firebaseio.com",
projectId: "contactform-4376b",
storageBucket: "",
messagingSenderId: "497947572169"
};
firebase.initializeApp(config);
var messagesRef = firebase.database().ref('messages');
var query1=messagesRef.orderByChild('Nom_client');
query1.on('value', gotData , errData);
function gotData(data){
event.preventDefault();
var names = data.val();
console.log(names);
var keys =Object.keys(names);
for (var i=0;i<keys.length;i++){
var k=keys[i];
var Nom_Client=names[k].Nom_client;
var Prenom_Client=names[k].Prenom_Client;
var Age_Client=names[k].Age_Client;
var Ville_Client=names[k].Ville_Client;
var Tel_Client=names[k].Tel_Client;
var Tel_Portable_Client=names[k].Tel_Portable_Client;
$(document).ready(function() {
$("#but").click(function (){
$("#0").html(Nom_Client+"</br>"+Prenom_Client+"</br>"+
Age_Client+"</br>"+Ville_Client+"</br>"+Tel_Client+"
</br>"+Tel_Portable_Client );
});
});
}}
function errData(err){
console.log('error');
console.log(err);
}
这是我的代码,请随意提出任何更改,因为我对javaScript有点新手,谢谢 这是我的数据库结构:
newMessageRef.set({
Nom_client:Nom_Client ,
Prenom_Client:Prenom_Client ,
Email_Client:Email_Client,
Tel_Client:Tel_Client,
Tel_Portable_Client:Tel_Portable_Client,
Ville_Client:Ville_Client,
Addresse_Client:Addresse_Client,
Age_Client:Age_Client,
Code_Postale_Client:Code_Postale_Client,
Description_Client:Description_Client
})