简体   繁体   English

在客户端(即在 javascript 中)检查 firebase db ref 的正确方法是什么?

[英]What is the correct way to check firebase db ref on client side(i.e. in javascript)?

While using firebaseDB.ref("some-node-ref-that-does-not-exist/") how can I make a null check.使用firebaseDB.ref("some-node-ref-that-does-not-exist/")如何进行 null 检查。 This line of code still getting invoked with even above node does not exists in my firebase db.在我的 firebase 数据库中,这行代码仍然被调用,即使是上面的节点也不存在。

If you want to check if there is data at a specific node in the Realtime Database, you have to query this node and look if the DataSnapshot exists.如果要检查实时数据库中特定节点是否有数据,则必须查询该节点并查看DataSnapshot是否存在。

With the JavaScript SDK you would do as follows, using the exists() method:使用 JavaScript SDK 您可以使用exists()方法执行以下操作:

ref.once('value')
  .then(function(dataSnapshot) {
    if (dataSnapshot.exists()) {....}
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用客户端技术(即Javascript)仅显示表的一部分 - Showing only part of a table using Client-side technologies, i.e. Javascript 在JavaScript中检查字符串是否为空(即仅包含空格)的最高性能方法? - The most performant way to check if a string is blank (i.e. only contains whitespace) in JavaScript? Javascript-查找平均价格(即小数点后四舍五入)的准确方法是什么? - Javascript - What is the ACCURATE way to find an average of prices (i.e., round decimals)? 有没有办法检查普通的香草 javascript object 而不是任何其他特殊类型的 object(即日期)? - Is there a way to check for just a plain vanilla javascript object as opposed to any other special kind of object (i.e. Date)? 在 JavaScript 中检查字符串相等性的正确方法是什么? - What is the correct way to check for string equality in JavaScript? 如何或什么是处理 webform 中客户端验证错误的正确方法? - How or What is the correct way to handle client side validation errors in webform? 在客户端将服务器端变量传递给 JavaScript 的最佳方法是什么? - What is the best way to pass server side variables to JavaScript on the client side? 像rails之类的partials仅使用纯JavaScript编写,并且完全在客户端执行。 --IE没有服务器 - partials like rails has only done in pure javascript, and purely on the clients side. --I.E. no servers 在 Vue 单元测试中模拟 webpack “externals”(即 jquery)的正确方法(使用 mocha) - Correct way to mock webpack “externals” (i.e. jquery) in Vue unit tests (using mocha) JavaScript一个接收伪整数(即0100或03)并输出正确整数的函数 - JavaScript a function that receives pseudo-integer (i.e. 0100 or 03) and outputs correct integer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM