{
"movies": {
"movie1": {
"genre": "comedy",
"name": "As good as it gets",
"lead": "Jack Nicholson"
},
"movie2": {
"genre": "Horror",
"name": "The Shining",
"lead": "Jack Nicholson"
},
"movie3": {
"genre": "comedy",
"name": "The Mask",
"lead": "Jim Carrey"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是Firebase的新手.我如何可以检索从上面的数据结果,其中genre = 'comedy'与lead = 'Jack Nicholson'?
我有什么选择?
情况:
我需要下载childNode,然后将()设置为另一个节点.
问题是我想在childNode的得分属性达到100时才这样做.
我应该在何时何地检查帖子的分数是否为100或更高,以及如何仅将其复制到新索引一次?
我的想法是什么:
加载帖子后,检查其分数.如果> = 100,请检查数据库是否属于这种情况.然后将节点推送到新索引.
问题:
每次加载帖子时,如何阻止节点上传,因为多次加载时得分> = 100?我需要它只发生一次!
解决方案代码:
if (funPost.score >= global.hotNumber && funPost.hot == false) {
var hotPostRef = firebase.database().ref("hot/section/"+key);
var hotPost = {
title: funPost.title,
image: funPost.image,
id: funPost.id,
key: funPost.key
}
hotPostRef.set(hotPost);
funPostRef.update({"hot": true});
}
else if (funPost.score <= (global.hotNumber - 25) && funPost.hot == true) {
var hotPostRef = firebase.database().ref("hot/section/"+key);
hotPostRef.remove();
funPostRef.update({"hot": false});
}
Run Code Online (Sandbox Code Playgroud)
解决方案:我最终使用了布尔标志.