加入聚合物和火力基地的查询 [英] Join queries with polymer and firebase

查看:138
本文介绍了加入聚合物和火力基地的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些理论上应该很简单的事情。在Firebase中我有以下数据结构:

$ $ $ $ $ $ $ $ $ $ $ b $ 1
--- name :一些项目
---组织:真棒组织
---用户
---- uid1:true
---- uid2:true

- 用户
- uid1
- 名称:鲍勃
---电子邮件:bob@test.com
---电话:020 3456 3456
- uid2
---名字:tom
---电子邮箱:tom@test.com
---电话:020 3456 3456

我有一个从父元素传递过来的项目id,我想显示该项目的所有用户。

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

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

< template is =dom-repeatitems ={{users}}as =u>
user key:[$ .key]]
<! - 现在做一些事情来检索完整的用户记录并显示它 - >
< / template>

< / template>
< / dom-module>

然后我如何得到每个用户的完整用户记录,我是否需要在里面有一个标签重复吗?但是,那么如何异步工作?



或者是不是这样做的正确方法?

谢谢很多为您的帮助。

解决方案

我会在这里重新发布我的解决方案,因为我无法弄清楚如何格式化代码

最终我把每个用户记录都放在自己的组件中,就像这样:

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

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

< template is =dom-repeatitems ={{users}}as =u>
< user-details uid = [[u。$ key]]>< / user-details>
< / template>

< / template>
< / dom-module>

然后在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>


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.

解决方案

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>

这篇关于加入聚合物和火力基地的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆