0

我想使用polymerfire元素来获取数据https://dinosaur-facts.firebaseio.com/dinosaurs并在元素中显示数据dom-repeat

我究竟做错了什么?我该如何正确地做到这一点?

这是 jsBin

http://jsbin.com/zeyimotasa/1/edit?html,控制台,输出
<!doctype html>
<head>
  <meta charset="utf-8">
  <!-- Source: https://github.com/Download/polymer-cdn -->
  <base href="https://cdn.rawgit.com/download/polymer-cdn/1.7.0.2/lib/">
  <!--- ->
  <base href="https://polygit.org/components/">
  <!--- ->
  Toggle below/above as backup when server is down
  <!--- ->
  <base href="https://polygit2.appspot.com/components/">
  <!---->
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="polymerfire/polymerfire.html" rel="import">
  <link href="paper-button/paper-button.html" rel="import">
</head>
<body>

<dom-module id="x-element">

<template>
  <style></style>

  <p>
    <paper-button on-tap="_handleClick">Click Me</paper-button>
  </p>
  <!---->
    <firebase-document
      path="https://dinosaur-facts.firebaseio.com/dinosaurs"
      data="{{dinosaurs}}"
      >
    </firebase-document>
    <template is="dom-repeat" items="[[dinosaurs]]">
      [[item.order]]
    </template>
    <template is="dom-repeat" items="[[test]]">
      [[item]]
    </template>
  <!---->

</template>

<script>
  (function(){
    Polymer({
      is: "x-element",
      properties: {
        dinosaurs: Array,
        test: {
          value: function() {
            return ['foo', 'bar', 'baz'];
          }
        },
      },
      _handleClick: function() {
        console.log('You clicked me!');
      }
    });
  })();
</script>

</dom-module>

<x-element></x-element>

</body>
4

2 回答 2

1

要以数组/集合形式获取数据,您需要使用<firebase-query>元素,而不是<firebase-document>. 您还需要使用以下命令初始化您的应用程序<firebase-app>

<firebase-app api-key="XXX" database-url="yyy" auth-domain="zzz"></firebase-app>
<firebase-query path="/dinosaurs" data="{{dinosaurs}}"></firebase-query>

<template is="dom-repeat" items="[[dinosaurs]]">
  <!-- ... -->
</template>
于 2016-11-18T18:38:41.243 回答
0

您需要一个<firebase-app>来初始化 Firebase 应用程序,不是吗?

于 2016-11-18T17:41:58.620 回答