I have a lightning-combobox component, that gets options from a javascript method.
What I am trying to do is to get one of those options, as default value in the html component.
Javascript method is something like this:
get options() {
var options = [];
if(this.sortData.sortRules){
this.sortData.sortRules.forEach(ele =>{
options.push({label:ele.label + ' ' + ele.direction , value:ele.sortRuleId});
});
}
return options;
}
The html element is like this:
<lightning-combobox
name="progress"
label="Sort:"
value={value}
placeholder="Sorting by"
options={options}
</lightning-combobox>
I want to know how to get the first option from options[] as default value in the combobox.
Anyone that can help me with this?
Best Answer
Assuming the options are available in connected callback, you can set a default value like this: