如何按值重复下拉列表选择下拉列表



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

最新更新