I'm implementing a polymer custom element using a native select with options.
<select id="selectbox" value="{{selectedId::change}}">
<template is="dom-repeat" items="{{arrayItems}}" >
<option value="{{item}}" id="{{item}}">{{item}}</option>
</template>
</select>
https://jsfiddle.net/fiddle_gabriela/a58L52yh/2/
The selectedId
represents the id of the item to be selected in the select box
(1 for the first element, 2 for the second, etc.).
At the creation of the select box I would like to select the 4th element in the list.
The problem is that selectedId
gets the value of the element (e.g. admission, alert, ...) and not its id.
How to get the id instead of the value?
update expected result (from comment)
<select>
<option value="admission">admission</option>
<option value="alert">alert</option>
<option value="bvt_sample">bvt_sample</option>
<option value="clinicalpath" selected > clinicalpath</option>
</select>
You can use a function to check if the current item is the same as the one actually selected.
<option value="{{item}}" id="{{item}}" selected="{{isSelected(item)}}">
isSelected: function(item) {
console.log(item);
return item === this.selectedId;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments