我想迭代Json结构并迭代地从顶部节点获取数据到最内层节点
我试过这个Child_added但它不起作用这是Json结构:
{
"0153" : {
"0163" : {
"Email" : "vikram@dept.com"
},
"Email" : "joel@dept.com"
}
}
这是我的代码:
var dbref=new Firebase("https://logintrialapp.firebaseio.com/Employee/OrgHierachy/0153");
var login=localStorage.getItem("Email");
var i=0;
var j=0;
dbref
.once("value")
.then(function(snapshot) {
j=j+1;
console.log("value is:",j);
console.log(snapshot.val());
snapshot.forEach(function(childsnapshot) {
i=i+1;
var newPlayer = childsnapshot.val();
console.log("email: " + newPlayer.Email);
console.log("key:"+ childsnapshot.key);
console.log(i);
});
});
这是o / p:
value is: 1
Checkworks.html:40 Object {0163: Object, Email: "joel@dept.com"}0163: ObjectEmail: "joel@dept.com"__proto__: Object
Checkworks.html:55 email: vikram@dept.com
Checkworks.html:57 key:function (){D("Firebase.DataSnapshot.key",0,0,arguments.length);return this.Y.key()}
Checkworks.html:59 1
Checkworks.html:55 email: undefined
Checkworks.html:57 key:function (){D("Firebase.DataSnapshot.key",0,0,arguments.length);return this.Y.key()}
Checkworks.html:59 2
如何从内部节点获取数据,同时保持相同的url作为参考,我的意思是现在我已经下降(OrgHierachy / 0153)到url中的内部节点来获取数据,是可以在保持对URL中最顶层节点的引用的同时获取数据。