Join queries with polymer and firebase

送分小仙女□ 提交于 2019-12-25 08:16:26

问题


I'm trying to do something which in theory should be simple. I have the following data structure in Firebase:

- projects
-- 1
--- name: some project
--- organisation: awesome organisation
--- users
---- uid1: true
---- uid2: true

- users
-- uid1
--- name: Bob
--- email: bob@test.com
--- tel: 020 3456 3456
-- uid2
--- name: tom
--- email: tom@test.com
--- tel: 020 3456 3456

I have a project id that is passed from a parent element, and I'd like to display all the users for that project.

<dom-module id="project-users">
  <template>

    <firebase-query 
      id="query" 
      path="/projects/{{project.id}}/users" 
      data="{{users}}">
    </firebase-query>

    <template is="dom-repeat" items="{{users}}" as="u">
      user key: [[u.$key]]
      <!-- now do something to retrieve the full user record and display it -->
    </template>

  </template>
</dom-module>

How would I then get the full user record for each user, would I need to have a tag inside the dom-repeat? But then how would that work asynchronously?

Or is that not the proper way to do it?

Thanks a lot for your help.


回答1:


I'll repost my solution here since I couldn't figure out how to format code in the comments :-)

Eventually I ended up putting each user record in its own component, like this:

<dom-module id="project-users">
  <template>

    <firebase-query 
      id="query" 
      path="/projects/{{project.id}}/users" 
      data="{{users}}">
    </firebase-query>

    <template is="dom-repeat" items="{{users}}" as="u">
      <user-details uid=[[u.$key]]></user-details>
    </template>

  </template>
</dom-module>

And then in user-details.html:

<dom-module id="user-details">
  <template>

    <firebase-document 
      path="/users/[[uid]]" 
      data="{{u}}">
    </firebase-document>

    [[u.name]]<br />
    [[u.email]]<br />
    [[u.tel]]<br />

  </template>
</dom-module>


来源:https://stackoverflow.com/questions/41334669/join-queries-with-polymer-and-firebase

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