如何使用 firebase-collection 创建对特定用户的引用?
How to create a reference to a specific user with firebase-collection?
我正在使用带有 firebase-collection 元素的 Polymer 1.1。
我想在我的数据库中检索特定用户的信息,结构如下:
<userId>
- name: "joe"
- email: "provider"
- fullName: "Joe Brown"
我的 firebase 集合有效,但我得到了所有用户的信息:
<firebase-collection
limit-to-first="1"
location="https://storklancer.firebaseio.com/users/"
data="{{users}}"></firebase-collection>
<template is="dom-repeat" items="[[users]]" as="user">
<span>Name: </span><span>[[user.fullName]]</span>
</template>
如果我输入 limit-to-first="3"
我会得到所有信息,但我需要来自特定用户的信息。假设此用户的 ID 为 1234:
<firebase-collection
limit-to-first="1"
location="https://storklancer.firebaseio.com/users/1234" // I thought that would work
data="{{users}}"></firebase-collection>
<template is="dom-repeat" items="[[users]]" as="user">
<span>Name: </span><span>[[user.fullName]]</span>
</template>
我需要 return 用户 1234 的 fullName
。是否可以使用 firebase-collection 元素,或者它只完成了 firebase way?
我建议使用 firebase-document 元素,而不是将位置设置为用户的路径,数据将是完整的用户信息。
更新代码:
<firebase-document
location="https://storklancer.firebaseio.com/users/1234"
data="{{user}}"></firebase-document>
然后在你的元素的 DOM 中是这样的:
<span>Name: </span><span>[[user.fullName]]</span>
我正在使用带有 firebase-collection 元素的 Polymer 1.1。
我想在我的数据库中检索特定用户的信息,结构如下:
<userId>
- name: "joe"
- email: "provider"
- fullName: "Joe Brown"
我的 firebase 集合有效,但我得到了所有用户的信息:
<firebase-collection
limit-to-first="1"
location="https://storklancer.firebaseio.com/users/"
data="{{users}}"></firebase-collection>
<template is="dom-repeat" items="[[users]]" as="user">
<span>Name: </span><span>[[user.fullName]]</span>
</template>
如果我输入 limit-to-first="3"
我会得到所有信息,但我需要来自特定用户的信息。假设此用户的 ID 为 1234:
<firebase-collection
limit-to-first="1"
location="https://storklancer.firebaseio.com/users/1234" // I thought that would work
data="{{users}}"></firebase-collection>
<template is="dom-repeat" items="[[users]]" as="user">
<span>Name: </span><span>[[user.fullName]]</span>
</template>
我需要 return 用户 1234 的 fullName
。是否可以使用 firebase-collection 元素,或者它只完成了 firebase way?
我建议使用 firebase-document 元素,而不是将位置设置为用户的路径,数据将是完整的用户信息。
更新代码:
<firebase-document
location="https://storklancer.firebaseio.com/users/1234"
data="{{user}}"></firebase-document>
然后在你的元素的 DOM 中是这样的:
<span>Name: </span><span>[[user.fullName]]</span>