Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将firebase结果附加到聚合物元素_Javascript_Jquery_Polymer 1.0_Firebase Polymer - Fatal编程技术网

Javascript 如何将firebase结果附加到聚合物元素

Javascript 如何将firebase结果附加到聚合物元素,javascript,jquery,polymer-1.0,firebase-polymer,Javascript,Jquery,Polymer 1.0,Firebase Polymer,我需要将这个聚合元素附加到index.html 我这样做没有问题,但问题是 我无法向“items”div追加任何内容 我该怎么做? 我认为元素尚未附加到index.html页面,因此脚本无法捕获“items”div 聚合物({ 是:“样本页”, }); $(文档).ready(函数(){ ; var rootRef=“myfirebase ref……” rootRef.on(“添加了child_”),函数(快照,prevChildKey){ var pointData=snapshot.val

我需要将这个聚合元素附加到index.html 我这样做没有问题,但问题是 我无法向“items”div追加任何内容 我该怎么做? 我认为元素尚未附加到index.html页面,因此脚本无法捕获“items”div


聚合物({
是:“样本页”,
});
$(文档).ready(函数(){
;
var rootRef=“myfirebase ref……”
rootRef.on(“添加了child_”),函数(快照,prevChildKey){
var pointData=snapshot.val();
snapshot.forEach(函数(childSnap){
$('#items').append(pointData.user);
var key=childSnap.key();
//console.log('herecome');
//日志(“标题:“+pointData.user”);
})
//  });
//  });

您需要等待聚合物元件/网组件加载完毕

而不是
$(document).ready(function(){})

使用下面的代码(或JQuery等效代码)

 <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>
window.addEventListener('WebComponentsReady', function(e) {
    ...
});