我試圖延遲加載Firebase項目,以便稍後加載更多的用戶,無論用戶何時到達div容器的末端。當我刪除.endAt()
和.startAt()
我收到了15件物品,雖然它們沒有增加,並且卡住了這15件物品。Firebase延遲加載
當我保持.endAt()
和.startAt()
我收到火力警告 Using an unspecified index. Consider adding ".indexOn": "title" at /items
即使.indexOn
設置。我被這個警告弄糊塗了。預先感謝您的幫助。
火力地堡結構
{
"items" : {
"-Kk6aHXIyR15XiYh65Ht" : {
"author" : "joe",
"title" : "Product 1"
},
"-Kk6aMQlh6_E3CJt_Pnq" : {
"author" : "joe",
"title" : "Product 2"
}
},
"users" : {
"RG9JSm8cUndpjMfZiN6c657DMIt2" : {
"items" : {
"-Kk6aHZs5xyOWM2fHiPV" : "-Kk6aHXIyR15XiYh65Ht",
"-Kk6aMTJiLSF-RB3CZ-2" : "-Kk6aMQkw5bLQst81ft7"
},
"uid" : "RG9JSm8cUndpjMfZiN6c657DMIt2",
"username" : "joe"
}
}
}
安全規則
{
"rules": {
".read": true,
".write": "auth != null",
"users":{
"$uid": {
".write": "$uid === auth.uid"
"items":{
".indexOn": "title",
"$itemId": {
"title": {".validate": "...}
"type": {".validate": "...}
}
}
}
}
}
}
}
代碼結構延遲加載
let _start = 0,
_end = 14,
_n = 15;
function lazyLoadItems(){
firebase.database().ref('items')
.orderByChild('title')
.startAt(_start)
.endAt(_end)
.limitToFirst(_n)
.on("child_added", snapshot=> console.log(snapshot.val()));
_start += _n;
_end += _n;
}
當您向'/ users/$ uid/items'添加索引時,您正在查詢'/ items'。 –
嗯,是的,雖然我想列出所有用戶的所有項目,所以查詢'/ users/$ uid/items'而沒有'uid'將無法完成這項工作。在''rules「中加入'.indexOn('items')'沒有任何意義。難道這是嚴格的規則嗎? – nehel
這是不可能與你分享的東西說。 JSON的最小片段可能會有所幫助。您可以通過點擊[Firebase數據庫控制檯](https://console.firebase.google.com/project/_/database/data)中的「導出JSON」鏈接來獲取此信息。 –