如何将一个childNode从一个节点复制到另一个节点?

情况:

我需要下载childNode,然后设置()到另一个节点。

问题是,只有当childNode的score属性达到100时,我才会这样做。

何时何地我应该检查post是否有100分或更高的分数,以及如何将它们复制到新的索引只有一次?


我想到了什么:

当一个post被加载,检查它的分数。 如果大于等于100,则检查数据库是否如此。 然后将节点推到新的索引。


问题:

我怎样才能防止每次加载post时都上传节点,因为在多次加载时得分> = 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}); } 

解决scheme:我结束了使用布尔标志。

我结束了一个布尔标志:

 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}); } 

尝试使用.once() .on()

  ref.once('value') .then(function(dataSnapshot) { // handle read data. }); 

https://gist.github.com/katowulf/6099042是你如何复制或移动参考其他裁判&#x3002;

我怎样才能防止每次加载post时都上传节点,因为在多次加载时得分大于等于100? 我需要它只发生一次!

1)如果path键已经存在()在新位置,则使用螺栓规则使写入失败。

2)是什么导致分数上升? 如调查完成,考试已完成这些事件应发送到firebase队列,可以运行一系列的pipe道来更新你所需要的任何东西。