Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Menu 如何在Polymer中重置纸张下拉菜单,以便不选择任何内容?_Menu_Reset_Polymer 1.0_Selected_Dropdown - Fatal编程技术网

Menu 如何在Polymer中重置纸张下拉菜单,以便不选择任何内容?

Menu 如何在Polymer中重置纸张下拉菜单,以便不选择任何内容?,menu,reset,polymer-1.0,selected,dropdown,Menu,Reset,Polymer 1.0,Selected,Dropdown,我想将聚合纸下拉菜单重置为JavaScript中的初始状态,因此不选择任何内容,因此看起来如下所示: 我可以在纸张下拉菜单内的纸张菜单标签上添加一个id,用JavaScript访问它并选择它的选定索引: document.getElementById("accountTypeMenu").selected = 1; 但是,我只能选择一个可用项目,因此该数字必须为0或更大。我无法将其设置为-1以选择nothing以直观地返回其初始状态,但我可以将所选状态记录为我刚刚设置的状态。我试图将选定的其

我想将聚合纸下拉菜单重置为JavaScript中的初始状态,因此不选择任何内容,因此看起来如下所示:

我可以在纸张下拉菜单内的纸张菜单标签上添加一个id,用JavaScript访问它并选择它的选定索引:

document.getElementById("accountTypeMenu").selected = 1;
但是,我只能选择一个可用项目,因此该数字必须为0或更大。我无法将其设置为-1以选择nothing以直观地返回其初始状态,但我可以将所选状态记录为我刚刚设置的状态。我试图将选定的其他值更改为空且未定义

以下是我用于纸张下拉菜单的html:

<paper-dropdown-menu 
id="accountTypeDropdown"
selected-item="{{selectedItem}}"
selected-item-label="{{selected}}"
label='&#65290;Account type' 
style="width:50%;"
noink 
no-animations>

    <paper-menu id="accountTypeMenu"
                class="dropdown-content"
                onmouseup="requiredMenuFieldSelected('accountType')">
                        <template is="dom-repeat"
                                  items="{{accountTypes}}"
                                  as="accountType">
                            <paper-item value="[[accountType.id]]">[[accountType.name]]</paper-item>
                        </template>
    </paper-menu>

</paper-dropdown-menu>

<input is="iron-input" 
       name="accountType" 
       type="hidden" 
       value$="[[selectedItem.value]]">

[[accountType.name]]

这是一个仅可用的字段。所以您可能必须使用Polymer提供的函数来设置仅准备就绪的值。试试下面的方法

document.getElementById("accountTypeDropdown")._setSelectedItem({});
如果上述方法不起作用,请尝试以下其他方法

document.getElementById("accountTypeDropdown")._setSelectedItem(null);
document.getElementById("accountTypeDropdown")._setSelectedItem();

您可以手动触发事件:

document.querySelector("#accountTypeDropdown")._onIronDeselect();

现在使用
似乎更好

使用它,您只需将
所选
设置为

<paper-dropdown-menu label="Type">
    <paper-listbox class="dropdown-content" selected="{{myObj.type}}" attr-for-selected="value" id="list">
        <paper-item value="0">Type 0</paper-item>
        <paper-item value="1">Type 1</paper-item>
    </paper-listbox>
</paper-dropdown-menu>

非常感谢。document.getElementById(“accountTypeDropdown”)。_setSelectedItem(null);作品重置与_setSelectedItem(null)一起工作,但是有一件奇怪的事情。仅当新值与重置前的值不同时,才可通过更改模型在之后设置新值。我在这里设置了一个测试用例:尝试在
纸质菜单上添加
selected={{{selectedMenu}}
。并在需要重置项目时设置
selectedMenu=null
this.$.list.selected = null;