Polymerfire dom-repeat with Firebase objects

风格不统一 提交于 2019-12-08 05:17:28

just use firebase-query instead of firebase-document. you'll get an array back.

<firebase-query
  app-name="contacts"
  path="/user"
  data="{{allUsers}}">
</firebase-query>

<template is="dom-repeat" items="{{allUsers)}}">
  <div class="profile card">
    {{item.FirstName}} 
  </div>
</template>

dom-repeat takes an array as the items property. You can do something like this:

<template is="dom-repeat" items="[[makeArray(allUsers)]]">

...

makeArray: function(items) {
  return Object.keys(items).map(function (key) {items[key]});
}

You forgot the return:

_makeArray: function(items) {
  return Object.keys(items).map(function (key) { return items[key]; });
}

Its works fine with me data are displayed just fine.

gerd hübner

Better implementation (also includes the name of the key if required) can be found here:

How to use dom-repeat with objects instead of arrays in Polymer 1.0?

Also an implementation for two way binding:

Two way binding for Firebase arrays in dom-repeat

Hope this gets implemented in Polymer 2.0, as Firebase is being advertised but then there are problems with using best practice Polymer and best practice Firebase together.

Use firebase-query to return an array of object that you can pass to dom-repeate.

  <firebase-query
   path="/user"
   data="{{allUsers}}"
   </firebase-query>

The dom-repeat

add attribute as="data"
add property data.$key

<template is="dom-repeat" items="{{_makeArray(allUsers)}}" as="data">
    <div class="profile card">
        {{data.$key}} 
        {{data.FirstName}} 
    </div>
</template>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!