firebase-realtime-database

How can I avoid code duplication when getting data from Firebase (android)?

白昼怎懂夜的黑 提交于 2020-03-18 03:05:12
问题 I'd imagine this question would apply to any application that uses asynchronous calls. I'm relatively new to all this, and the problem I'm having is with with fetching data from Firebase to my Android application. There are several classes throughout the application that need to use data from the "users" table in the database, which I obtain as follows: DatabaseReference reference = FirebaseDatabase.getInstance().getReference() .child("users").child("exampleDataFromUsers"); reference

How can I avoid code duplication when getting data from Firebase (android)?

浪尽此生 提交于 2020-03-18 03:04:21
问题 I'd imagine this question would apply to any application that uses asynchronous calls. I'm relatively new to all this, and the problem I'm having is with with fetching data from Firebase to my Android application. There are several classes throughout the application that need to use data from the "users" table in the database, which I obtain as follows: DatabaseReference reference = FirebaseDatabase.getInstance().getReference() .child("users").child("exampleDataFromUsers"); reference

How to calculate sum of object keys in array - javascript

狂风中的少年 提交于 2020-03-17 12:05:31
问题 Question I am working with firebase and react native. I have returned an array from my firebase database that looks like this. [Object, Object, Object] Under each object I have returned a single item, "level:4". So I have three objects containing 4,5,6. How do I sum these together? Thanks! 回答1: Either a simple loop var a = [{level:1},{level:2},{level:3},{level:4}], total = 0; for (var i=0; i<a.length; i++) { total += a[i].level; } console.log('total', total) or reduce var a = [{level:1},

How to calculate sum of object keys in array - javascript

假如想象 提交于 2020-03-17 12:03:59
问题 Question I am working with firebase and react native. I have returned an array from my firebase database that looks like this. [Object, Object, Object] Under each object I have returned a single item, "level:4". So I have three objects containing 4,5,6. How do I sum these together? Thanks! 回答1: Either a simple loop var a = [{level:1},{level:2},{level:3},{level:4}], total = 0; for (var i=0; i<a.length; i++) { total += a[i].level; } console.log('total', total) or reduce var a = [{level:1},

Making firebase storage public for reading and writing on android

扶醉桌前 提交于 2020-03-17 10:22:10
问题 I am new to firebase storage. Can anyone tell me how to make the storage files public for reading and writing?. The default code provided by firebase is given below. What changes should I make ? service firebase.storage { match /b/image-view-b1cf5.appspot.com/o { match /{allPaths=**} { allow read, write: if request.auth != null; } } } 回答1: The documentation explains that if no rule expression is provided, the rule evaluates to true: service firebase.storage { match /b/image-view-b1cf5.appspot

Read data from firebase swift

。_饼干妹妹 提交于 2020-03-17 09:42:11
问题 I'm trying to retrieve data from firebase database, but when I run the code it display nothing, though no errors shown I got this piece of code from Firebase manual, by the way, I'm pretty sure that the path is correct let ref = FIRDatabase.database().reference() ref.child("users").child("user").child(username).observeSingleEvent(of: .value, with: { (snapshot) in // Get user value let value = snapshot.value as? NSDictionary let score = value?["score"] as? String ?? "" print(score) // ... }) {

Cant convert object of type java.util.Arraylist Read from Firebase realtim database nested objects

泄露秘密 提交于 2020-03-16 07:38:32
问题 This Firebase database structure: enter image description here Here is my Device Class: public class Device { private String title; private Map<String,Counters> CounterNumber; private Counters counters; public void setCounter(Map<String,Counters> CounterNumber){ this.CounterNumber=CounterNumber; } public Map<String,Counters> getCounter(){ return CounterNumber; } public Counters getCounters(){ return counters; } public void setCounters(Counters counters){ this.counters=counters; } public

how delete a specific node in firebase?

℡╲_俬逩灬. 提交于 2020-03-05 07:27:21
问题 I hooked up firebase and made the save data in it. But I can't delete a specific entry in firebase. I tried deleting through method that I wrote below. But it doesn't work. final FirebaseDatabase _database = FirebaseDatabase.instance; delData(String phoneNumber) {_database.reference() .child('phoneNumber') .remove() .then((_) { print("Delete $phoneNumber successful"); setState(() { // }); }); } Update the method that I was advised by Frank van Puffelen does not work correctly, it removes all

Reading nested data from Firebase returns something else than an array

时间秒杀一切 提交于 2020-03-05 06:04:50
问题 Trying to read (and expect) a nested array like this: var array = [ 0: {subArrayy: {...}, title: "Title"}, 1: {subArray]: {...}, title: "Title"}, ... However after reading and (!) outputting, the result is fine. My web console shows me the array and everything seems good. BUT doing array.length returns 0. And any iteration returns undefined. I've tried using ladosh _.toArray thing that I've seen earlier, but it does absolutely nothing. var locations = []; // Empty array var ref = db.ref(

Reading nested data from Firebase returns something else than an array

狂风中的少年 提交于 2020-03-05 06:04:19
问题 Trying to read (and expect) a nested array like this: var array = [ 0: {subArrayy: {...}, title: "Title"}, 1: {subArray]: {...}, title: "Title"}, ... However after reading and (!) outputting, the result is fine. My web console shows me the array and everything seems good. BUT doing array.length returns 0. And any iteration returns undefined. I've tried using ladosh _.toArray thing that I've seen earlier, but it does absolutely nothing. var locations = []; // Empty array var ref = db.ref(