首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Polymerfire从Firebase检索数据

用Polymerfire从Firebase检索数据
EN

Stack Overflow用户
提问于 2016-08-09 16:55:56
回答 1查看 638关注 0票数 1

我现在从聚合火开始,尝试做一个小的应用程序,把一些存储在Firebase上的数据作为纸卡列出。我使用了google示例中的一些代码来构建应用程序,如下所示:

index.html

代码语言:javascript
复制
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
    <title>Beer Cellar</title>
      <link rel="manifest" href="manifest.json">      
    <style>
      body {
        margin: 0;
      }
    </style>
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/polymerfire/firebase-app.html">
<link rel="import" href="beer-list-app.html">      
  </head>
  <body>   
      <firebase-app
    name="BeerCellar"
    api-key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    auth-domain="beercellar-627fc.firebaseapp.com"
    database-url="https://beercellar-627fc.firebaseio.com">
</firebase-app>
<beer-list-app></beer-list-app>
  </body>
</html>

beer-list-app.html

代码语言:javascript
复制
<link rel="import" href="bower_components/polymerfire/polymerfire.html">
<link rel="import" href="bower_components/paper-card/paper-card.html">
<dom-module id="beer-list-app">
    <template>
    <firebase-query
        id="query"
        log
        app-name="BeerCellar"
        path="/brands"
        data="{{branddata}}">
    </firebase-query>

    <template is="dom-repeat" items="[[branddata]]" as="brand">

        <paper-card heading="[[brand.name]]">
      <div class="card-content">[[brand.origin]]</div>
    </paper-card>
    </template>
</template>
    <script>
    Polymer({
      is: 'beer-list-app',
        properties: {
        uid: String,
        branddata: {
          type: Object,
          observer: 'dataChanged'
        }
      },

      dataChanged: function (newData, oldData) {
        // do something when the query returns values
          console.log("NewData: " + newData);
      }
    });
    </script>
</dom-module>

然而,这似乎不起作用,也没有显示任何东西。我已经将日志属性添加到firebase-query中,并在控制台上获得了以下内容:

代码语言:javascript
复制
Initializing stored value.
polymer-micro.html:673 Polymer::Attributes: couldn`t decode Array as JSON
app-storage-behavior.html:350 Got stored value! undefined {{branddata}}

我尝试用相同的结果将模板上的项更改为[branddata]。

错误抛出的高聚物-micro.html代码:

代码语言:javascript
复制
deserialize: function (value, type) {
switch (type) {
case Number:
value = Number(value);
break;
case Boolean:
value = value != null;
break;
case Object:
try {
value = JSON.parse(value);
} catch (x) {
}
break;
case Array:
try {
value = JSON.parse(value);
} catch (x) {
value = null;
console.warn('Polymer::Attributes: couldn`t decode Array as JSON');
}
break;

根据Chrome工具,JSON.parse的变量值包含{branddata}或[branddata],这取决于我如何在模板上定义它。

我错过了一些东西。

编辑:,我改变了一些啤酒列表-app.html,添加了dom-模块。现在,json错误已经消失,日志显示如下:

代码语言:javascript
复制
Initializing stored value.
beer-list-app.html:33 BrandData: 
app-storage-behavior.html:350 Got stored value! undefined []

编辑2: i根据getbuckts的建议,从beer app.html中的数据更改函数中修改代码。我的控制台将newData记录为空。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-02-27 15:08:31

您是否已登录到应用程序中?在决定看我的许可之前,我也遇到过同样的问题。尝试更改您的权限。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38856512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档