我试图延迟加载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”链接来获取此信息。 –