如何 Select 按值下拉 dom-重复下拉
How to Select Dropdown by Value dom-repeat Dropdown
我正在尝试在 Polymer 中刷新页面后重新加载下拉设置。下拉列表从 AJAX 调用动态加载,一旦下拉列表被设置,它就会保存在 localStorage 中。
<select id="customer" on-change="selectCustomer">
<option value="" selected disabled>Select Customer</option>
<template is="dom-repeat" items="[[customers]]" as="customer" index-as="index">
<option value="[[customer]]">[[customer]]</option>
</template>
</select>
...
selectCustomer() {
localStroage.setItem("customerName", this.$.customer.value = index;"
)
我试过了
setDropdown() {
// index generated in text matching for loop
this.$.customer.selectedIndex = index;
)
和
setDropdown() {
// customerName generated in text matching for loop
this.$.customer.value = customerName;
)
我相信更好的方法是将您的下拉值绑定到属性 customer
然后观察 customer
的值并将其保存到本地存储...将其同步到 connectedCallback
a demo is always the best way to explain ...
我正在尝试在 Polymer 中刷新页面后重新加载下拉设置。下拉列表从 AJAX 调用动态加载,一旦下拉列表被设置,它就会保存在 localStorage 中。
<select id="customer" on-change="selectCustomer">
<option value="" selected disabled>Select Customer</option>
<template is="dom-repeat" items="[[customers]]" as="customer" index-as="index">
<option value="[[customer]]">[[customer]]</option>
</template>
</select>
...
selectCustomer() {
localStroage.setItem("customerName", this.$.customer.value = index;"
)
我试过了
setDropdown() {
// index generated in text matching for loop
this.$.customer.selectedIndex = index;
)
和
setDropdown() {
// customerName generated in text matching for loop
this.$.customer.value = customerName;
)
我相信更好的方法是将您的下拉值绑定到属性 customer
然后观察 customer
的值并将其保存到本地存储...将其同步到 connectedCallback
a demo is always the best way to explain ...