gpt4 book ai didi

javascript - 如何检查 key 是否存在于节点中?

转载 作者:行者123 更新时间:2023-12-01 01:51:04 24 4
gpt4 key购买 nike

enter image description here

这是结构。我有一个主节点,里面有 key 。如何检查该节点内是否存在特定 key ?

 let ref = firebase.database().ref(userID);
ref.orderByKey().equalTo(key).on("child_added", function(snapshot) {
document.getElementById('chat_box').style.display = 'none';
console.log("This ad is posted by you - " + userID) ;
});

最佳答案

有一个exists可以调用的函数。

let ref = firebase.database().ref('yourNode/yourKey');

ref.once("value")
.then(function(snapshot) {
console.log(snapshot.exists()); // true
}

关于javascript - 如何检查 key 是否存在于节点中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51515912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com