fb-util 无限滚动中的 $key 问题
Issue with $key in fb-util infinite scroll
我正在使用 fb-util 进行无限滚动,一切看起来都不错。但是,一旦我达到 250 个元素,我就会看到以下错误。知道这是关于什么的吗?
Error: Query: When ordering by key, you may only pass one argument to
startAt(), endAt(), or equalTo(). at 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)
at r._grow (https://<>/content/script/firebase-util.min.js:10:8979) at
r._listen (https://<>/content/script/firebase-util.min.js:10:10961) at
r.goTo (https://<>/content/script/firebase-util.min.js:10:8062) at
r.moveTo (https://<>/content/script/firebase-util.min.js:10:3672) at
r.next (https://<>/content/script/firebase-util.min.js:10:17083) at
https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:198:424
at xa.(anonymous function)
(https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:59:133)
at 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,停止产生错误。但是,这导致较早的元素被替换。
因此,虽然我对问题的第一部分没有答案,但根据附加说明,我有以下解决方法:
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.
我正在使用 fb-util 进行无限滚动,一切看起来都不错。但是,一旦我达到 250 个元素,我就会看到以下错误。知道这是关于什么的吗?
Error: Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo(). at 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) at r._grow (https://<>/content/script/firebase-util.min.js:10:8979) at r._listen (https://<>/content/script/firebase-util.min.js:10:10961) at r.goTo (https://<>/content/script/firebase-util.min.js:10:8062) at r.moveTo (https://<>/content/script/firebase-util.min.js:10:3672) at r.next (https://<>/content/script/firebase-util.min.js:10:17083) at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:198:424 at xa.(anonymous function) (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:59:133) at 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,停止产生错误。但是,这导致较早的元素被替换。
因此,虽然我对问题的第一部分没有答案,但根据附加说明,我有以下解决方法:
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.