如何将两个Polymer的firebase-collection元素嵌入dom-repeat中?

Ant*_*olm 5 data-binding firebase polymer firebase-polymer polymer-1.0

我有一个问题是循环两个Polymers firebase-collection元素.使用我的数据库结构,我首先要检查用户有权访问哪些事件,然后从事件中获取有关该事件的信息.

这段代码的问题在于,当我循环第二个firebase-collection时,"events"上的数据绑定在所有重复上都是相同的,因此它在每个h4上都是相同的名称.

那么有没有办法在data ="{{}}"中拥有一个唯一的变量.还是有更好的方式来写出数据?

<firebase-collection data="{{userData}}" location="{{_getCorrectUrl()}}"></firebase-collection> 
<template is="dom-repeat" items="{{userData}}" as="user">
  <firebase-collection data="{{events}}" location="{{_getCorrectEventsUrl(user.__firebaseKey__)}}" ></firebase-collection> 
  <template is="dom-repeat" items="{{events}}" as="event">
    <h4>{{event.value.name}}</h4>
  </template>
</template>
Run Code Online (Sandbox Code Playgroud)

Sal*_*leh 2

我有一个解决方案,我认为这不是解决这个问题的最佳方法,但它对我有用。我创建了另一个名为“my-user”的元素,我公开了一个名为“user”的属性,该属性从第一个 dom-repeat 中分配了 user 的值。一切正常,但是,我对这个解决方案不满意。我仍在寻找一种不涉及为此创建专用元素的解决方案。

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

和另一个“我的用户”:

<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>
Run Code Online (Sandbox Code Playgroud)

编辑

现在,在回答这个问题一段时间后,我开始意识到,当有人使用 NoSQL 数据库遇到这种情况时,通常会凸显出设计中的问题。数据应该是非规范化的,并且应该避免像 SQL 数据库中通常所做的那样进行连接。在 YouTube 上观看 The Firebase Database For SQL Developers