Javascript 聚合物&x2B;Firebase(Polymerfire):无法读取属性';推动';未定义的';:';这是$.query.ref.push(…)和#x27;

Javascript 聚合物&x2B;Firebase(Polymerfire):无法读取属性';推动';未定义的';:';这是$.query.ref.push(…)和#x27;,javascript,firebase,firebase-realtime-database,polymer,Javascript,Firebase,Firebase Realtime Database,Polymer,我正在使用Polymer应用程序工具包(由Polymer CLI启动)进行以下操作 当我尝试将数据推送到Firebase集合时,出现以下错误: 无法读取未定义的属性“push” 以下是我的代码(firebase应用程序在my-app.html中启动,名称为“firebase应用程序”): 首先,我建议将您的代码与进行比较,这样可以更清楚地向您揭示问题 this.$.query.ref(.ref)引用了Polymer.FirebaseDatabaseBehavior的属性,该属性具有: 注意db

我正在使用Polymer应用程序工具包(由Polymer CLI启动)进行以下操作

当我尝试将数据推送到Firebase集合时,出现以下错误:

无法读取未定义的属性“push”

以下是我的代码(firebase应用程序在my-app.html中启动,名称为“firebase应用程序”):



首先,我建议将您的代码与进行比较,这样可以更清楚地向您揭示问题

this.$.query.ref
.ref
)引用了
Polymer.FirebaseDatabaseBehavior
的属性,该属性具有:

注意
db.ref(path)
,因此
ref
null
必须是
if
语句的结果。评估每种情况可能会发现问题:

  • db==null

    • 此属性来自
      app.database()
      (),或者在未定义时设置为
      null
      (由
      )。在导入使用
      的元素之前,是否已使用正确的
      应用程序名称声明
  • path==null

    • 你可能还没有准备好。情况显然并非如此
    • 路径组件之一可能是空字符串或未初始化。对于您的路径(
      /users/[[user.uid]]/models
      ),可能尚未定义
      user
      (用户尚未登录),这会导致路径组件中出现空字符串(
      /users//models
  • this.disabled

    • 你可能已经准备好了。情况显然并非如此

惊人、合乎逻辑且解释清楚的答案!问题在于第一点:firebase应用程序未正确导入:我在另一个模块中配置了firebase应用程序
,因此我可以轻松地在我的应用程序中重用firebase数据<代码>
位于我的主应用程序容器视图中(
my app.html
)。如果我将
我的app.html
移动到
add model.html
,它可以工作,但我在
我的app.html
中有功能,这也需要
。两次加载模块返回
未捕获错误:名为“Firebase App”的Firebase应用程序已经存在。
发布了一个关于我之前评论的新问题:再次感谢您的深入解释。@Dean没问题:)您能看看我的其他问题(第二条评论中的链接)吗?这就是我在应用程序中声明
时遇到的问题。我整个上午都在想这个问题,但一直没能解决。当然,如果今天晚些时候没有人来回答,我会尽力回答的。
<dom-module id="add-model">
    <!-- Defines the element's style and local DOM -->
    <template>
        <firebase-auth user="{{user}}" app-name="firebase-app"></firebase-auth>
        <firebase-query
                app-name="firebase-app"
                id="query"
                path="/users/[[user.uid]]/models"
                data="{{model}}">
        </firebase-query>
        <paper-input id="modelName" label="Model Name" "></paper-input>
        <paper-button class="create" id="create" on-tap="create" raised>Create</paper-button>
    </template>
    <!-- Creates the element's prototype and registers it -->
    <script>
        Polymer({
            is: 'add-model',
            properties: {
                data: {
                    type: Object
                }
            },
            create: function() {
               this.$.query.ref.push({
                   name: this.$.modelName.value
                });
            }
        });
    </script>
</dom-module>
__computeRef: function(db, path) {
  if (db == null ||
      path == null ||
      !this.__pathReady(path) ||
      this.disabled) {
    return null;
  }

  return db.ref(path);
},