How to extend paper-dropdown-menu for a reusable custom element list?

五迷三道 提交于 2019-12-24 03:57:30

问题


I have a list of time zones that needs to be a reusable component. How do I make my list of time zones a reusable component in Polymer? I need this custom element to provide whether a time zone was selected (isSelected) and a function or property to get the selected time zone name.

This is driving me mad!

Thanks in advance. Below is a component file called, 'time-zones.html'. I removed all the BS JavaScript I was trying because clearly it wasn't working. The only thing working is the loading of the list.

<link rel="import" href="../polymer/polymer.html">

<link rel="import" href="../paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../paper-dropdown/paper-dropdown.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../paper-item/paper-item.html">


<polymer-element name="lt-timezones-input" attributes="timezones">
    <template>
        <style>    
            paper-dropdown-menu {
              box-sizing: border-box;
              width: 100%;
            }

            core-menu {
              box-sizing: border-box;
              width: 90%;
            }

            paper-item {
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
        </style>
        <paper-dropdown-menu id="ddl" label="Time Zone">
            <paper-dropdown class="dropdown">
                <core-menu class="menu">
                    <template id="list" repeat="{{timezones}}">
                      <paper-item>{{}}</paper-item>
                    </template>
                </core-menu>
            </paper-dropdown>
        </paper-dropdown-menu>
        <!-- shadow DOM here -->
    </template>
    <script>
        Polymer('lt-timezones-input', {
            created: function () {

                this.timezones = [
                    'Eastern Standard Time',
                    'Central Standard time',
                    'Mountain Standard Time',
                    'Pacific Standard Time'
                ];
            }
        });
    </script>    
</polymer-element>

回答1:


Here is one possible solution: Plunk

core-select event is used here.

<paper-dropdown-menu on-core-select="{{item_changed}}">


来源:https://stackoverflow.com/questions/30512699/how-to-extend-paper-dropdown-menu-for-a-reusable-custom-element-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!