How to extend paper-dropdown-menu for a reusable c

2019-07-15 08:12发布

问题:

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}}">