javascript
  • jquery
  • polymer-1.0
  • firebase-polymer
  • 2016-01-05 22 views 0 likes 
    0

    我需要追加這種聚合物元素的index.html 我做到了,沒有問題,但問題是我 不能追加什麼是「項目」的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> 
    

    回答

    0

    您需要等到聚合物元素/網頁組件加載完畢。

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

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

    window.addEventListener('WebComponentsReady', function(e) { 
        ... 
    }); 
    
    相關問題