如何按价值dom-repeat Dropdown选择下拉列表

时间:2018-02-05 15:07:43

标签: javascript drop-down-menu polymer polymer-2.x dom-repeat

我在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;
)

1 个答案:

答案 0 :(得分:2)

我认为更好的方法是将您的下拉列值绑定到属性customer,然后观察customer的值并将其保存到本地存储...在connectedCallback上同步a demo is always the best way to explain ......