I have a combobox whose values are supposed to be dynamically added. For some reason this is not happening. I have found similar cases on this website but none of the solutions worked for me. Here is my code.
JS Code :
@track items = []; //this will hold key, value pair
connectedCallback(){
getContactList()
.then(result => {
{
this.contacts = result;
for (var i = 0; i < this.contacts.length; i++) {
var contact = this.contacts[i];
console.log('contact:', contact);
this.items.push({ label: contact.channel, value: contact.channel });
}
console.log('this.items.length:', this.items.length);
console.log('this.items:', this.items);
console.log('deserialized items :', JSON.stringify(this.items));
}
})
.catch(error => {
this.error = error;
});
}
HTML
<div class="slds-col"> <lightning-combobox
name="elChannel"
label="Channel"
value={value}
placeholder="Select Channel"
options={items}
onchange={genericOnChange} >
</lightning-combobox></div>
The console output shows that items is being filled properly, it is just not appearing in the combobox. The thing I don't understand is that contacts is displayed in a datatable and is updated properly when calling the function.