i'm developing lightning web component and i want to fill or populate my combobox from result of apex method so how i can in the html file get the result from JavaScript file and put them in the combobox.
Template:
<lightning-combobox
name="Role"
label="Role Name"
value={value}
placeholder=""
options={rolesList.data.values}
onchange={handleChange} >
</lightning-combobox>
javascript file:
import { LightningElement, track, wire} from 'lwc';
import getRoles from '@salesforce/apex/LeaveSettingsController.getRoles';
@wire(getRoles)
rolesList;
Best Answer
Though I am late in answering this question, but here is the other approach to populate combo box values.
Controller
Here retrieve UserRole records based on SOQL query and no data transformation in this class
js Controller class
In this class, inside
wiredUserRoles()
method, perform data transformation for value and label.Use,
roleOptions()
getter property to return the array.HTML
Output
After selection, display the value.