我这里有一个我要从firebase中检索的对象的屏幕截图。
我就是这样做的
table
我得到了这个回复
这不是我想要的,我期待这样的事情
constructor(){
super();
this.state = {
items: []
};
}
componentWillMount(){
this.firebaseRef = new Firebase('https://sweltering-heat-7923.firebaseio.com/contact/-KF1XUgOvcrybku8Q52s');
this.firebaseRef.once("value", function (snapshot){
snapshot.forEach(function(data){
console.log(data.val());
}.bind(this));
}.bind(this));
}
你会怎么做?
答案 0 :(得分:2)
您正在迭代contact/-KF1XUgOvcrybku8Q52s
的所有子节点并逐个记录它们。要获取完整对象,请使用snapshot.val()
代替snapshot.forEach(...)
:
this.firebaseRef.once('value', function(snapshot){
console.log(snapshot.val());
});