Firebase Keyed JSON to convert into items for Polymer iron-list; or access nested JSON?

128 Views Asked by At

I've tried lots of options to get Firebase Key-indexed JSON to display db text and images (from storage) into divs and template by using getElementById and it works for only setting the elements of the last db record received for the template. But I'm trying a Polymer iron-list... and just can't get it.

I can't use iron-ajax since the firebase database url gives CORS header errors. I've tried creating a Polymer property Array that returns a function, but that works only for a hardcoded array that I manually removed to key from to test.

I've looked at Firebase Document and Firebase Collection, which refer to Firebase Query... but I can't figure out how to change oldData for newData in an observer function, and data's not going to change much, not yet anyway. And trying to set iron-list items = a Polymer property Array with a computed function option doesn't even get to invoke that part of the property code for some reason.

  1. How should Firebase Key-indexed JSON content be put automatically into a dom-repeat Tempate and into an Iron-list please?

It seems to go against grain to manipulate and iterate through the Object converted to Array in a for-loop like some answers suggest. But if the only option i would, what would be needed is to convert eg:

{"-KcKDbyGIwd.." :{ UserId : "Tri0IP..MruqLs1",desc : "king's horses"}, ..., {} }, to:

{ UserId : "Tri0IP..MruqLs1", desc : "king's horses"}, ..., {}

  1. How do I strip the key off each record please?

Thanks a lot in advance for your help...

1

There are 1 best solutions below

1
On

This should work!

  <iron-list items="[[data]]" as="item">
    <template>
      <div>
        Name: [[item.name]]
      </div>
    </template>
  </iron-list>