我正在尝试在聚合物中刷新页面后重新加载下拉设置。 下拉列表从 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
演示始终是解释的最佳方式......