0

I have tried to figure this out with similar questions already asked, but can't seem to get it. This is what I get back from firebase:

'{"users":[null,{"-JFhOFSUwhk3Vt2-KmD1": {"color":"White","model":"650i","year":"2014","make":"BMW"}, "-JGW6vwYtnfoIxeQlwCq": {"color":"Red","model":"AMG","year":"2014","make":"Mercedes"}},{"-JFhNnaAq1rr_SHzJcIr":{"color":"Red","model":"F150 FX4","year":"2014","make":"Ford"}},{"-JFhYXNpUG3wSMcfB3Uz":{"color":"Blue","model":"AMG","year":"2014","make":"Mercedes"}},null,null,null,{"- JFly1lt6UWj-r2985ed":{"color":"red","model":"650i","year":"2014","make":"bmw"}}]}'

These cars are from 2 different users, I would like to put the information in a table. How would I use parse to do this? Here is what the call looks like:

$scope.read = function () {
    $http.get(BaseUrl + ".json").success(function (data) {
        $scope.AllCars = data
    });
}

Right now I can login with each user and show the cars they have entered on a table using Angular. Every time time they add one, it automatically adds another row. I would like for any user to see their cars as well as every other users. My goal is to retrieve this data and put into a separate table. The information will be constantly changing so I assume I would need to set the code up to expect changes.

Here is my firebase data:

 users
 1
 -JFhOFSUwhk3Vt2-KmD1
 color: "White"
 make: "BMW"
 model: "650i"
 year: "2014
 -JGW6vwYtnfoIxeQlwCq
 color: "Red"
 make: "Mercedes"
 model: "AMG"
 year: "2014"
 2
 -JFhNnaAq1rr_SHzJcIr
 color: "Red"
 make: "Ford"
 model:  "F150 FX4"
 year: "2014"
 3
 -JFhYXNpUG3wSMcfB3Uz
 color: "Blue"
 make: "Mercedes"
 model: "AMG"
 year: "2014"
 7

1 Answer 1

2

if you want all the cars in a single object:

var all={};
data.users.filter(Boolean).forEach(function(user){
  Object.keys(user).map(function(k){  all[k]=this[k];  }, user);
});

console.log(all);

which shows something like

Object {-JFhOFSUwhk3Vt2-KmD1: Object, -JGW6vwYtnfoIxeQlwCq: Object, -JFhNnaAq1rr_SHzJcIr: Object, -JFhYXNpUG3wSMcfB3Uz: Object, - JFly1lt6UWj-r2985ed: Object…}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.