2015-02-11 155 views
0

如何訪問聚合物元素內部的外部元素。如何訪問聚合物元素內部的外部元素

<polymer-element attributes="externalDropZoneContainerId">> 
<script> 
    Polymer('file-upload', { 
     ready: function(){ 
      //Here I want to access the externalDropZoneContainerId so that I can bind drag and drop functionality to this ID 
      //$('#' + externalDropZoneContainerId) does not work. 
     } 
    }) 
</script> 
<polymer-element> 

回答

0

屬性是通過this.externalDropZoneContainerId訪問,標準DOM API來獲取元素是document.getElementById

<polymer-element attributes="externalDropZoneContainerId">> 
<script> 
    Polymer('file-upload', { 
     ready: function(){ 
      var elem = document.getElementById(this.externalDropZoneContainerId); 
     } 
    }) 
</script> 
<polymer-element> 

取而代之的是ready事件,你也許應該使用domReady事件代替,否則其他元件可以尚未保證存在。

+0

對不起。我沒有測試這個,因爲我發現一個工作不是這樣的。我會盡快進行測試,並會更新您的答案 – sam113 2015-02-12 14:33:55