简体   繁体   中英

Aurelia - Set default value in dropdown

I have a drop-down which is populated from a JavaScript array.

let a = [90, 95, 99];

When I bind this array in the HTML as follows, the initial value is set to 90.

<select>
    <option repeat.for="i of a">${i}</option>
</select>

But I need to show '95' as the default value. So how can I achieve this?

You can bind the value of the select to a certain value, which it will take as default.

let a = [90, 95, 99];
let selectedValue = 95;

Html:

<select value.bind="selectedValue">
    <option repeat.for="i of a">${i}</option>
</select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM