如何将火球结果附加到聚合物元素中

How to append firebase result to a polymer element

本文关键字:聚合物 元素 火球 结果      更新时间:2023-09-26

我需要将这个聚合物元素附加到index.html我做的没有问题,但问题是我不能将任何内容附加到"items"div我该怎么做?我认为元素还没有附加到index.html页面,所以脚本无法捕获"items"div。

 <link rel="import" href="../bower_components/polymer/polymer.html">
    <script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
    <link rel="import" href="../bower_components/paper-icon-button">
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>

    <dom-module id="sample-page">
      <style>

      </style>
      <template>
        <div class="items">

        </div>
      </template>
    </dom-module>
    <script>
      Polymer({
        is: "sample-page",
      });
        $(document).ready(function(){
      ;
      var rootRef = "myfirebase ref......."
      rootRef.on("child_added", function (snapshot, prevChildKey) {
        var pointData = snapshot.val();
        snapshot.forEach(function (childSnap) {
         $('#items').append( pointData.user);
          var key = childSnap.key();
    //console.log('here come');
    //      console.log("Title: " + pointData.user);
        })
    //  });

      //  });
    </script>

您需要等待,直到加载了聚合物元素/web组件。

代替$(document).ready(function(){});

使用以下代码(或JQuery等效代码)

window.addEventListener('WebComponentsReady', function(e) {
    ...
});