如果满足特定条件,我正在尝试从下拉列表中选择第二个选项,但遇到问题selectedIndex
<select id="contact" on-change="selectContact">
<option value="-1" selected>Select Contact</option>
<template is="dom-repeat" items="[[contacts]]" as="contact" index-as="index">
<option value="[[contact]]">[[contact]]</option>
</template>
</select>
<select id="name" on-change="selectName">
<option value="-1" selected>Select Name</option>
<template is="dom-repeat" items="[[names]]" as="name">
<option value="[[name]]">[[name]]</option>
</template>
</select>
...
selectContact() {
for (let i = 0; i < this.customerTable[0].length; i++) {
if(true) {
array[i] = this.customerTable[0][i]['name'];
}
}
this.names = this.$.util.utilFn(array);
if(this.names.length == 1) {
this.shadowRoot.querySelector('#name').selectedIndex = 2;
}
}
如何选择 dom-repeat 下拉列表的第二个子项?