如何动态将项目添加到paper-dropdown菜单中? [英] How can I dynamically add items into paper-dropdown-menu?

查看:75
本文介绍了如何动态将项目添加到paper-dropdown菜单中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用dropdownMenu.appendChild(menuItem)之类的方式添加它,但是正如我所期望的那样,它不起作用.我在Polymer指南中找不到与此相关的信息,也在这里找不到其他类似的问题.

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 questions on here.

有可能吗?如果可以,怎么办?

Is that possible? If so, how?

paper-dropdown-menu: https://elements.polymer-project. org/elements/paper-dropdown-menu

paper-dropdown-menu: https://elements.polymer-project.org/elements/paper-dropdown-menu

推荐答案

在Polymer中,推荐的操作DOM的方法是通过操作数据:

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

  • 将数组中的菜单项列表放入:var items_array = [....];

-将菜单创建为:

<paper-dropdown-menu label="Your favourite pastry">
  <paper-listbox class="dropdown-content">
    <template is="dom-repeat" items="{{items_array}}">
      <paper-item>{{item}}</paper-item>
    </template>
  </paper-listbox>
</paper-dropdown-menu>

  • items_array中添加和删除元素将立即影响菜单.
    • adding and removing elements in items_array will affect the menu immediately.
    • 这篇关于如何动态将项目添加到paper-dropdown菜单中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆