在fb-util无限滚动中使用$ key的问题

时间:2016-12-20 08:52:54

标签: angularjs firebase firebase-realtime-database nginfinitescroll

我使用fb-util进行无限滚动,一切看起来都不错。但是,一旦我点击了250个元素,我就会看到以下错误。知道这是关于什么的吗?

  

错误:查询:按键排序时,您只能传递一个参数   startAt(),endAt()或equalTo()。在Jh   (https://www.gstatic.com/firebasejs/3.2.1/firebase.js:431:117)at   X.g.Nd(https://www.gstatic.com/firebasejs/3.2.1/firebase.js:441:298)   在r._grow(https://<> /content/script/firebase-util.min.js:10:8979)at at   r._listen(https://<> /content/script/firebase-util.min.js:10:10961)at at   r.goTo(https://<> /content/script/firebase-util.min.js:10:8062)at at   r.moveTo(https://<> /content/script/firebase-util.min.js:10:3​​672)at at   r.next(https://<> /content/script/firebase-util.min.js:10:17083)at at   https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:198:424   在xa。(匿名函数)   (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:59:133)   在l。$ eval   (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:84

代码:

var baseRef = firebase.database().ref().child(refPath);
var scrollRef = new firebase.util.Scroll(baseRef, '$key');
scrollRef.scroll.next(25);
var list = $firebaseArray(scrollRef);
list.scroll = scrollRef.scroll;

前端代码:

<div infinite-scroll="vm.products.scroll.next(10)" infinite-scroll-distance="1">

nb:将密钥从$ key更改为$ priority或name或productid,停止产生错误。但是,这导致了早期的元素被替换。

1 个答案:

答案 0 :(得分:0)

所以,虽然我对问题的第一部分没有答案,但基于附加说明,我有这个问题:

var scrollRef = new firebase.util.Scroll(baseRef, '$priority', {maxCacheSize: 750, windowSize: 500});

将maxCacheSize和windowSize设置为更高的值可以解决问题。根据文档,如果我们超过windowSize,则会修剪数组的开头以保持大小不受限制。

文档:

Keys/values that can be passed via opts:

{int} windowSize: the maximum number of records to have loaded in the list at any given time. 3-5 times the size of the viewable window is a good optimization, depending on how fast content is scrolled and the payload of each record (i.e. how long it takes to download).
{int} maxCacheSize: in general, leave this as the default. This controls the internal cursor's cache, which is used to find the current position in the list. This controls how many keys it can load at any given time. This is, by default, three times the size of windowSize and should always be larger than windowSize.