![](/img/trans.png)
[英]Angularjs: How to check if element's children contains certain element (by ID)
[英]How to check if parent element contains a certain tag? - Polymer
我將代碼分成不同的文件(簡化版):
admin-page.html
<paper-tabs selected={{selected}} attr-for-selecton="name">
<paper-tab name="User">User</paper-tab>
...
...
</paper-tabs>
<iron-pages selected={{selected}} attr-for-selection="name">
<admin-user-page name="User"></admin-user-page>
...
...
</iron-pages>
admin-user-page.html
<!-- general page content... -->
// Javascript
//--------------
// here I want to have an if statement for whether the parent (user-page.html)
// contains the <paper-tabs> tag.
記住我正在尋求PolymerJS解決方案,是否有任何方法可以從admin-user-page.html文件中檢測admin-page.html中是否存在paper-tabs
?
好吧,在您的子組件(管理員用戶頁面)中,您可以使用this.parentNode訪問您的父組件(管理員頁面),然后檢查是否有paper-tabs標簽。 所以看起來像這樣:
Polymer('admin-user-page', {
ready: function(){
// you have to use parentNode twice
// this.parentNode is the iron-pages
// this.parentNode.parentNode is the admin-page
if( this.parentNode.parentNode.querySelector('paper-tabs') ){
// paper-tabs tag exists in parent
}
}
});
但是,這不是一個優雅的解決方案。 但我希望能回答您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.