我正在尝试将嵌套模板与聚合物一起使用,但我无法获取具有该类的所有元素
menu--item__has_submenu
.
代码:
<template>
<nav class="page-nav">
<button class="menu--link close_menu" on-click="_toggleMenu">
<div class="menu--icon">
<br-icons class="nav-btn-icon" icon="br-icons:close"></br-icons>
</div>
</button>
<ul class="menu js-menu">
<template is="dom-repeat" items="{{items}}">
<li class="menu--item menu--item__has_submenu" on-click="_toggleSubmenu">
<a href="{{item.link}}" class="menu--link" title="{{item.label}}">
<div class="menu--icon" data-icon="{{item.icon}}">
<br-icons icon="br-icons:user"></br-icons>
</div>
<span class="menu--text">{{item.label}}</span>
</a>
<ul class="submenu">
<template is="dom-repeat" items="{{item.submenu}}">
<li class="submenu--item">
<a href="{{item.link}}" class="submenu--link">{{item.label}}</a>
</li>
</template>
</ul>
</li>
</template>
</ul>
</nav>
</template>
Polymer({
is: 'br-nav',
properties: {
items: {
type: Array,
value: []
}
},
ready: function () {
},
_toggleMenu: function () {
Polymer.dom(this).classList.toggle('page-nav__opened');
},
_toggleSubmenu: function(e){
console.log(Polymer.dom(this).querySelectorAll('menu--item__has_submenu'));
//returns empty array
},
});