0

I was able to retrieve back the data but they were formatted as bunch of Objects instead of 1 Array. So here is my code:

team-list.html

<dom-module id="team-list">
<template>
<firebase-document
   id="query"
   app-name="appname"
   path="/teams/"
   data="{{teamDatas}}">
</firebase-document>

<template 
   is="dom-repeat"
   items="{{teamDatas}}"
   as="teamData">
 <team-item teamData="{{teamData}}"></team-item>
</template>

</template>
<script>
Polymer({
  is: 'team-list',
  properties:{
    teamDatas: Array,
}
});
</script>
</dom-module>

team-item.html

<dom-module id="team-item">
<template>
  <p> {{teamData.teamTag}}</p>
</template>
<script>
  Polymer({
    is: 'team-item',
    properties: {
   teamData: Object,
 }
});
</script>
</dom-module>

{{teamDatas}} return as 4 Objects instead of 1 Arrays

Expected array for items, found Object {-KPZg55u6YQg3EoywQCV: Object, -KPZg7XEsXbhCc854ZEQ: Object, -KPZg8no-OMP-PVIdcj9: Object, -KPZgq-0ql_ihuEcEnSV: Object}

My Json is as follow:

{
 "teams" : {
  "-KPZg55u6YQg3EoywQCV" : {
      "leader" : "iU1RPyyjAzPfqnes4PdEpGQLaaH3",
      "teamName" : "dsazxc",
      "teamTag" : "zxc"
},
  "-KPZg7XEsXbhCc854ZEQ" : {
},
  "-KPZg8no-OMP-PVIdcj9" : {
},
  "-KPZgq-0ql_ihuEcEnSV" : {
}
}

What wrong with my code?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Le nguyen
  • 1
  • 3

1 Answers1

0

Your JSON is wrong, you are using curly brace which are for Objects, you need to use square braces for Arrays ! Check w3c syntax

If I get you right, you want

{
    "teams" : 
    [
        "-KPZg55u6YQg3EoywQCV" : {
            "leader" : "iU1RPyyjAzPfqnes4PdEpGQLaaH3",
            "teamName" : "dsazxc",
            "teamTag" : "zxc"
         },
         "-KPZg7XEsXbhCc854ZEQ" : {
         },
         "-KPZg8no-OMP-PVIdcj9" : {
         },
         "-KPZgq-0ql_ihuEcEnSV" : {
         }
     ]
}

It represent an Object, which contains an Array of Objects.

Gregoire
  • 749
  • 6
  • 15
  • Thanks @GrégoireFruleux, the data was retrieved from firebase realtime database and firebase structure the database like that. So should i have a script to turn the Object to an Array, or there are a specific way to deal with firebase data – Le nguyen Aug 20 '16 at 20:35
  • @Lenguyen did you ever figured out the solution to this problem? if yes, can you please share, thanks! – securecodeninja Aug 28 '16 at 21:06