2016-08-02 33 views
0

我有嵌套像組件以下:聚合物 - 如何查詢嵌套的組件

<first-component> 
 
    <second-component> 
 
     <third-component></third-component> 
 
    </second-component> 
 
</first-component>

如何查詢選擇第三方組件?

在Chrome中,document.querySelector('third-component')起作用,但它不在Firefox中。

謝謝你們:)

+0

那麼Firefox究竟發生了什麼? –

+0

在Firefox中,當我嘗試查詢嵌套組件時,有一個控制檯錯誤表示它爲空,我想是因爲它找不到它。 – Richard

回答

0

如果你是在聚合物的定義,你可以使用this.$$(third-component)

否則,您應該在標籤上設置一個id。如果使用Polymer,則可以使用document.querySelector('#id')this.$.id

+0

爲什麼'querySelector'不能在Firefox上使用? –