【发布时间】:2016-03-17 14:42:43
【问题描述】:
我正在使用 firebase 和 Angular 2 构建一个小应用程序。
一切进展顺利,但现在我遇到了一个小问题。当我检索数据时,在控制台中我有我的所有数据(3 个对象)。但应用只显示其中一个(数据库中的最后一个)。
我已经看过这个stackoverflow question。
但它似乎不是同一个问题
我正在以这种方式检索数据:
loadTask() {
return Observable.create((observer) => {
this.geoQuery.on("key_entered", function(key, location, distance) {
this.usersRef = new Firebase('https://FBRUL.firebaseio.com/users/');
this.publicationRef = new Firebase('https://FBRUL.firebaseio.com/task/');
this.publicationRef.orderByKey().equalTo(key).on("child_added", (snapshot) =>{
this.publications = snapshot.key();
this.publicationRef.child(this.publications).on("child_added", snapshot => {
this.__publi = snapshot.val();
this.__key = snapshot.key();
let publicio = [];
this.publicationnass = {nom: this.__publi.nom, skills: this.__publi.skills, bugdet: this.__publi.budget, distance: Math.floor(distance), date: this.__publi.date, location: this.__publi.location, attribue: this.__publi.attribue, id1:this.publications, id: this.__key, offres: this.__publi.offres, user: this.__publi.user }
publicio.push(this.publicationnass)
observer.next(publicio)
})
})
})
})
}
}
这是我的案例plunker link的plnkr
如您所见,数据都在控制台中,但只显示一个。谁能帮我解决这个问题?
【问题讨论】:
标签: javascript firebase angular