Skip to content Skip to sidebar Skip to footer

How Can I Dynamically Add Items Into Paper-dropdown-menu?

I tried adding it with like dropdownMenu.appendChild(menuItem) but as I expected this doesn't work. I couldn't find information about this on Polymer's guides nor other similar que

Solution 1:

In Polymer, recommended way of manipulating the DOM is by manipulating the data:

  • put the list of menu items in array: var items_array = [....];

-create the menu as:

<paper-dropdown-menulabel="Your favourite pastry"><paper-listboxclass="dropdown-content"><templateis="dom-repeat"items="{{items_array}}"><paper-item>{{item}}</paper-item></template></paper-listbox></paper-dropdown-menu>
  • adding and removing elements in items_array will affect the menu immediately.

Solution 2:

Found out the proper way from their docs:

Should select the Polymer element with: Polymer.dom(parent).querySelector(selector)

And append with: Polymer.dom(parent).appendChild(node)

Post a Comment for "How Can I Dynamically Add Items Into Paper-dropdown-menu?"