How do you nest two of Polymer's firebase-collection elements inside dom-repeat?

心已入冬 提交于 2019-12-05 10:08:05

I have a solution which I consider not the best way to solve this issue, but it works for me. I created another element called 'my-user, I exposed an attribute called user which is assigned the value of user from the first dom-repeat. Everything works, however, I am not satisfied with this solution. I am still looking for a solution which doesn't involve creating a dedicated element for that.

<firebase-collection data="{{userData}}" location="{{_getCorrectUrl()}}">
</firebase-collection> 
<template is="dom-repeat" items="{{userData}}" as="user">
  <my-user user="[[user]]"></my-user>
</template>

and the other 'my-user':

<dom-module id="my-user">
<template>
  <firebase-collection data="{{events}}" location="{{_getCorrectEventsUrl(user)}}" ></firebase-collection> 
  <template is="dom-repeat" items="{{events}}" as="event">
    <h4>{{event.value.name}}</h4>
  </template>
</template>
<script>
    (function () {
  Polymer({
    is: 'my-user',
    _getCorrectEventsUrl: function(obj) {
      return 'https://app.firebaseio.com/users/' + obj.__firebaseKey__;
    },
    properties: {
      user:{
        type:Object,
      },
    },

  });
})();
</script>
</dom-module>

EDIT

Now after sometime of answering this question I came to realize that when someone face such a situation with NoSQL database, it usually highlights a problem in the design. Data should be de-normalized and one should avoid joining like what is normally done in SQL databases. Watch the The Firebase Database For SQL Developers on youtube.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!