如何访问polymerjs元素中的外部元素

时间:2015-02-11 06:44:38

标签: polymer

如何访问polymerjs元素内的外部元素。

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

1 个答案:

答案 0 :(得分: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事件,否则可能无法保证其他元素存在。