firebase.auth().onAuthStateChanged((user) => {
if (user) {
database = firebase.database();
var dbRef = firebase.database().ref().child('Agents').child(newarray[i]).orderByKey();
dbRef.on('value', newAgents, errData);
}
})
function newAgents(data) {
var container = document.getElementById("team");
container.innerHTML = '';
data.forEach(function(AgentSnap) { // loop over all jobs
console.log(AgentSnap.key);
var Agents = AgentSnap.val();
var AgentCard = `
<div class= "profilepics" id="${key}">
<figure ><img src=${Agents.profilepicurl}><figcaption>${Agents.Fname}</figcaption></figure>
</div>
`;
container.innerHTML += AgentCard;
})
}
但是firebase datasnapshot键的控制台日志显示了此
答案 0 :(得分:0)
您将监听器附加到单个代理:
var dbRef = firebase.database().ref().child('Agents').child(newarray[i]).orderByKey();
这意味着传递给回调的快照将包含单个代理的属性。然后在你的监听器中循环遍历快照的子节点。这意味着您最终会迭代AuthId
,Fname
,Lname
。
要获取所有座席,请将侦听器附加到/Agents
:
var dbRef = firebase.database().ref().child('Agents').orderByKey();