我尝试使用firebase数据进行无限滚动。 You can see this referance。当用户向下滚动时,有一种简单的分页。在这种情况下,一种曾经的倾听者#34;适用于
this.movieService
.getMovies(this.batch+1, this.lastKey)
.do(movies => {
/// set the lastKey in preparation for next query
this.lastKey = _.last(movies)['$key']
const newMovies = _.slice(movies, 0, this.batch)
/// Get current movies in BehaviorSubject
const currentMovies = this.movies.getValue()
/// If data is identical, stop making queries
if (this.lastKey == _.last(newMovies)['$key']) {
this.finished = true
}
/// Concatenate new movies to current movies
this.movies.next( _.concat(currentMovies, newMovies) )
})
.take(1)
.subscribe()
但我试图做实时应用程序,当用户调用一个动作时,它没有响应一些新数据。因此,我删除了take(1)。当我这样做时,会有一些重复数据,因为将触发侦听器,当侦听器触发时,它将连接两个数组。
我们的数组是对象数组,我希望在使用第二个数组进行dublicate时更新第一个数组。例如,第一个数组就像,
[{ $key :"1",firstname:"Ben",lastname:"Fried",point:1 },
{ $key :"2",firstname:"Carlo",lastname:"Strozzi",point:5},
{ $key :"3",firstname:"Jim",lastname:"DuBois",point:8}]
和第二个数组就像,
[{ $key :"2",firstname:"Carlo",lastname:"Strozzi",point:3}
{ $key :"4",firstname:"Larry",lastname:"Page",point:10 }]
我们的连接数组必须是
[{ $key :"1",firstname:"Ben",lastname:"Fried",point:1 },
{ $key :"2",firstname:"Carlo",lastname:"Strozzi",point:3},
{ $key :"3",firstname:"Jim",lastname:"DuBois",point:8},
{ $key :"4",firstname:"Larry",lastname:"Page",point:10 }]
注意:$ key是唯一的。
答案 0 :(得分:0)
如果订单不重要(或者您可以在合并后对您进行排序),您可以创建一个对象,该文档按$key
索引文档,并覆盖现有的{{1如果$keys
alread作为对象中的$key
存在。
以下是一个示例代码段:
key