我在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;
)
答案 0 :(得分:2)
我认为更好的方法是将您的下拉列值绑定到属性customer
,然后观察customer
的值并将其保存到本地存储...在connectedCallback
上同步a demo is always the best way to explain ......