Как добавить результат пожарной базы к полимерному элементу

Мне нужно добавить этот полимерный элемент в index.html, что я сделал без проблем, но проблема в том, что я не могу ничего добавить к этому элементу "items" div, как я могу это сделать? я думаю, что элемент еще не добавлен на страницу index.html, поэтому скрипт не может перехватить div "items".

 <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>

1 ответ

Вам нужно дождаться загрузки полимерных элементов / веб-компонентов.

Вместо $(document).ready(function(){});

Используйте код ниже (или эквивалент JQuery)

window.addEventListener('WebComponentsReady', function(e) {
    ...
});
Другие вопросы по тегам