问题
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