问题描述:

I have a Google Map in which all markers are to be publicly available. Only authenticated/logged in users can write markers and associated info to the DB.

My understanding is that the rules below will allow anyone to read the mapinfo route and only logged in users can write to it and that's what I want.

"mapinfo":{

".read" : true,

"$user_id": {

".write": "$user_id === auth.uid",

},

},

When I try to read from the database with the authenticated user, I only get the authenticated user's markers (as expected):

var mapitems = firebase.database().ref('mapinfo/'+firebase.auth().currentUser.uid);

I thought if I remove the current authenticated user from the route, then I would retrieve all the markers:

var mapitems = firebase.database().ref('mapinfo/');

This is returning the results, but not in the expected data structures.

How can I return all these results? Is it possible to say something like this:

var mapitems = firebase.database().ref('mapinfo/[ANY-USER]');

网友答案:

I sorted this by iterating over snapshop.val() and pushing the value, which is an object, on to the mapInfoItems array.

    var mapitems = firebase.database().ref('mapinfo/');
    mapitems.on('child_added', function(snapshot){
        $.each(snapshot.val(), function(key, value) {
            mapInfoItems.push(value);
            deferred.resolve(mapInfoItems);
        });
    });
相关阅读:
Top