找到你要的答案

Q:Polymer paper-dropdown-menu initialy selected not displayed in label

Q:本文初步选定的聚合物下拉菜单不显示的标签

Using the following code I would like "Option 1" to be displayed on page load. Instead "Label Here" is displayed. When clicking the drop down Option 1 is in bold showing it is selected. If I click Option 1 then the label updates and is correct

<paper-dropdown-menu label="Label Here" selected="0">
<paper-menu class="dropdown-content" selected="0">
<paper-item >Option 1</paper-item>
<paper-item >Option 2</paper-item>
</paper-menu>
</paper-dropdown-menu>

This is using the latest component from Github

  "dependencies": {
    "polymer": "1.0.8",
    "iron-elements": "1.0.3",
    "paper-elements": "PolymerElements/paper-elements#1.0.3",
    "page": "1.6.3",
    "adal-angular": "1.0.4",
    "moment": "2.10.6",
    "jaydata": "1.3.6",
    "bootstrap": "3.3.5",
    "paper-dropdown-menu": "PolymerElements/paper-dropdown-menu#1.0.1"

  }

Is this a bug or am I doing something wrong?

Thanks!

Daniel

使用下面的代码,我想“选项1”将显示在页面加载。取而代之的是“标签在这里”显示。当单击下拉选项1是粗体显示它被选中。如果我点击选项1然后标签更新并且是正确的

<paper-dropdown-menu label="Label Here" selected="0">
<paper-menu class="dropdown-content" selected="0">
<paper-item >Option 1</paper-item>
<paper-item >Option 2</paper-item>
</paper-menu>
</paper-dropdown-menu>

这是用从GitHub的新组件

  "dependencies": {
    "polymer": "1.0.8",
    "iron-elements": "1.0.3",
    "paper-elements": "PolymerElements/paper-elements#1.0.3",
    "page": "1.6.3",
    "adal-angular": "1.0.4",
    "moment": "2.10.6",
    "jaydata": "1.3.6",
    "bootstrap": "3.3.5",
    "paper-dropdown-menu": "PolymerElements/paper-dropdown-menu#1.0.1"

  }

这是一个错误还是我做错了什么?

谢谢!

丹尼尔

answer1: 回答1:

The selected attributes works with paper-menu, not with paper-dropdown-menu. But the latter's selectedItemLabel is computed and selectedItem is readOnly. The only way I found to preload selected item is to fire 'iron-activate' event, not sure that it's optimal though.

<dom-module id="my-test">
    <template>
        <paper-dropdown-menu id="dropdownMenu" label="Label Here" >
            <paper-menu id="menu" class="dropdown-content" selected="0">
                <paper-item id="option1">Option 1</paper-item>
                <paper-item id="option2">Option 2</paper-item>
            </paper-menu>
        </paper-dropdown-menu>
    </template>
    <script>
        Polymer({
            is: 'my-test',
            ready: function(){


                this.$.menu.dispatchEvent(new CustomEvent('iron-activate', {
                    bubbles: true,
                    cancelable: true,
                    detail: {
                        item:this.$.option2,
                        selected:1
                    }
                }));
            }
        });
    </script>
</dom-module>

选定的属性与文件菜单,下拉菜单中没有纸。但后者的selecteditemlabel计算和SelectedItem是只读的。唯一的方法,我发现预选定项目是火'铁激活'事件,不确定它是最佳的,虽然。

<dom-module id="my-test">
    <template>
        <paper-dropdown-menu id="dropdownMenu" label="Label Here" >
            <paper-menu id="menu" class="dropdown-content" selected="0">
                <paper-item id="option1">Option 1</paper-item>
                <paper-item id="option2">Option 2</paper-item>
            </paper-menu>
        </paper-dropdown-menu>
    </template>
    <script>
        Polymer({
            is: 'my-test',
            ready: function(){


                this.$.menu.dispatchEvent(new CustomEvent('iron-activate', {
                    bubbles: true,
                    cancelable: true,
                    detail: {
                        item:this.$.option2,
                        selected:1
                    }
                }));
            }
        });
    </script>
</dom-module>
answer2: 回答2:

Just an update that this is a known bug and is not intended behavior, even though the above workaround may work:

https://github.com/PolymerElements/paper-dropdown-menu/issues/3

Hopefully the issue will be resolve soon!

只是一个更新,这是一个已知的错误是无意的行为,虽然上述方法可以工作:

https://github.com/polymerelements/paper-dropdown-menu/issues/3

希望这个问题很快就能解决!

polymer  polymer-1.0