在尝试阅读所有相关内容之后,我真的无法传递包含纸质列表框的表单的值。我的代码是这样的:
<paper-dropdown-menu label="Location" name="page_parent" class="md" selected-item-label="{{selected}}">
<paper-listbox class="dropdown-content">
<paper-item value="1">First choice</paper-item>
<paper-item value="2">Second choice</paper-item>
<paper-item value="3">Third choice</paper-item>
</paper-listbox>
</paper-dropdown-menu>
<input is="iron-input" name="title" type="hidden" value$="[[selected]]">
$title 值的内容为空。
最佳答案
根据 https://www.polymer-project.org/1.0/docs/devguide/data-binding.html :
Data binding binds a property or sub-property of a custom element (the host element) to a property or attribute of an element in its local DOM (the child or target element).
这意味着输入将无法看到 paper-dropdown-menu 的属性,因为:
- paper-dropdown-menu 不是输入的父级
- paper-dropdown-menu 和 input 不共享父级
要解决这个问题,您可以创建一个新的自定义元素,以便两者共享一个父元素:
<body>
<dom-module id="my-element">
<template>
<paper-dropdown-menu label="Location" name="page_parent" class="md">
<paper-listbox class="dropdown-content" selected="{{myChoice}}">
<paper-item>First choice</paper-item>
<paper-item>Second choice</paper-item>
<paper-item>Third choice</paper-item>
</paper-listbox>
</paper-dropdown-menu>
<input is="iron-input" bind-value="[[myChoice]]">
</template>
<script>
Polymer({
is: 'my-element'
});
</script>
</dom-module>
<my-element></my-element>
</body>
paper-dropdown-menu 也没有 selected-item-label 属性
关于html - 获取表单中的 polymer 纸列表选定项值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33671000/