如何将一个childNode从一个节点复制到另一个节点? [英] How to copy a childNode from one node to another?
问题描述
$ b
我需要下载childNode,然后将其设置()到另一个节点中。
b$ b
问题是我只想在childNode的score属性达到100的时候这样做。
何时何地应该检查帖子是否有100分或更高的分数,如何将它们复制到新的索引只有一次?
什么想法:
当一篇文章被加载,检查它的分数。如果大于等于100,则检查数据库是否如此。然后将节点推到新的索引。
问题: 我怎样才能防止节点每次加载后上传,因为它在多个负载上的得分大于等于100?我需要它只发生一次! 解决方案代码: 解决方案:我结束了使用布尔标志。 最后,我用一个布尔标志来做: SITUATION: I would need to download the childNode, then set() it into the other node. Problem is I want to do this only once the childNode's score attribute reaches 100. Where and when should I check if posts have a score of 100 or more and how would I copy them to the new index only once ? WHAT I THOUGHT OF: When a post is loaded, check for it's score. If it's >= 100, check in the database if that's the case. Then push the node to the new index. PROBLEM: How would I prevent the node from being uploaded each time the post is loaded since it's score is >= 100 on multiple loads ? I need it to happen only once ! SOLUTION CODE:
Solution: I ended up using a boolean flag. I ended up doing it with a boolean flag:
这篇关于如何将一个childNode从一个节点复制到另一个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
if(funPost.score> = global.hotNumber&& funPost.hot == false){
var hotPostRef = firebase。 。数据库()REF( 热/部分/ +键);
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( 热/部分/ +键);
hotPostRef.remove();
funPostRef.update({hot:false});
if(funPost.score> = global.hotNumber&& funPost.hot == false){
var hotPostRef = firebase.database()。 REF( 热/部分/ +键);
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( 热/部分/ +键);
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});
}
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});
}