簡體   English   中英

如何將childNode從一個節點復制到另一個節點?

[英]How to copy a childNode from one node to another?

情況:

我需要下載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});
   }

解決方案:我最終使用了布爾標志。

我最終用一個布爾標志來做它:

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您是如何復制或移動ref到另一個參考。

每次加載帖子時,如何阻止節點上傳,因為多次加載時得分> = 100? 我需要它只發生一次!

1)如果路徑鍵已經存在()在新位置,則使用bolt規則使寫入失敗。

2)導致分數上升的原因是什么? 例如,調查已完成,考試已完成這些事件應發送到firebase隊列,該隊列可運行一系列管道以更新您需要的任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM