You need to sign in to do that
Don't have an account?

i cant show data of countries using combobox in lwc
apex controller
public with sharing class CoronaTableLWC {
public static List<CronaWrapLWC> CountryWrapperList{get;set;}
@AuraEnabled(Cacheable=true)
public static List<CronaWrapLWC> ConList(){
CountryWrapperList = new List<CronaWrapLWC>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://api.covid19api.com/countries');
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
CountryWrapperList=(List<CronaWrapLWC>)json.deserialize(res.getbody(),List<CronaWrapLWC>.class);
//CountryWrapperList.sort();
}
return Countrywrapperlist;
}
public with sharing class CronaWrapLWC {
@AuraEnabled
public String Country{get;set;}
}
controller.js
import { LightningElement, wire, track } from 'lwc';
import ConData from '@salesforce/apex/CoronaTableLWC.ConData';
import ConList from '@salesforce/apex/CoronaTableLWC.ConList';
let i=0;
export default class CoronaRecord extends LightningElement {
@track columns = [ { label: 'Country', fieldName: 'Country',type: 'text', sortable: "true"},
{ label: 'Confirmed', fieldName: 'Confirmed',type: 'text', sortable: "true"},
{ label: 'Deaths', fieldName: 'Deaths', type: 'text',sortable: "true"},
{ label: 'Recovered', fieldName: 'Recovered',type: 'text', sortable: "true" },
{label: 'NewDate', fieldName: 'NewDate', type: 'date', sortable:"true"}]
//@track error;
@track data ;
@track countryData;
@track error; //this holds errors
@track items = []; //this holds the array for records with value & label
@track value = '';
@track sortBy;
@track sortDirection;
@wire(ConList)
wiredContacts({ error, data }) {
if (data) {
for(i=0; i<data.length; i++) {
console.log('id=' + data[i]);
this.items = [{value: data}];
}
this.error = undefined;
} else if (error) {
this.error = error;
this.contacts = undefined;
}
}
get statusOptions() {
console.log(this.items);
return this.items;
}
handleChange(event) {
// Get the string of the "value" attribute on the selected option
const selectedOption = event.detail.value;
console.log('selectedOption=' + selectedOption);
}
}
html
<template>
<lightning-card title="CORONA CHART" icon-name="standard:contact" >
<lightning-combobox
name="contacts"
label="Contacts"
placeholder="Choose Contact"
value={value}
onchange={handleChange}
options={statusOptions}>
</lightning-combobox>
</template>
public with sharing class CoronaTableLWC {
public static List<CronaWrapLWC> CountryWrapperList{get;set;}
@AuraEnabled(Cacheable=true)
public static List<CronaWrapLWC> ConList(){
CountryWrapperList = new List<CronaWrapLWC>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://api.covid19api.com/countries');
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
CountryWrapperList=(List<CronaWrapLWC>)json.deserialize(res.getbody(),List<CronaWrapLWC>.class);
//CountryWrapperList.sort();
}
return Countrywrapperlist;
}
public with sharing class CronaWrapLWC {
@AuraEnabled
public String Country{get;set;}
}
controller.js
import { LightningElement, wire, track } from 'lwc';
import ConData from '@salesforce/apex/CoronaTableLWC.ConData';
import ConList from '@salesforce/apex/CoronaTableLWC.ConList';
let i=0;
export default class CoronaRecord extends LightningElement {
@track columns = [ { label: 'Country', fieldName: 'Country',type: 'text', sortable: "true"},
{ label: 'Confirmed', fieldName: 'Confirmed',type: 'text', sortable: "true"},
{ label: 'Deaths', fieldName: 'Deaths', type: 'text',sortable: "true"},
{ label: 'Recovered', fieldName: 'Recovered',type: 'text', sortable: "true" },
{label: 'NewDate', fieldName: 'NewDate', type: 'date', sortable:"true"}]
//@track error;
@track data ;
@track countryData;
@track error; //this holds errors
@track items = []; //this holds the array for records with value & label
@track value = '';
@track sortBy;
@track sortDirection;
@wire(ConList)
wiredContacts({ error, data }) {
if (data) {
for(i=0; i<data.length; i++) {
console.log('id=' + data[i]);
this.items = [{value: data}];
}
this.error = undefined;
} else if (error) {
this.error = error;
this.contacts = undefined;
}
}
get statusOptions() {
console.log(this.items);
return this.items;
}
handleChange(event) {
// Get the string of the "value" attribute on the selected option
const selectedOption = event.detail.value;
console.log('selectedOption=' + selectedOption);
}
}
html
<template>
<lightning-card title="CORONA CHART" icon-name="standard:contact" >
<lightning-combobox
name="contacts"
label="Contacts"
placeholder="Choose Contact"
value={value}
onchange={handleChange}
options={statusOptions}>
</lightning-combobox>
</template>
@wire(ConList)
wiredContacts({ error, data }) {
if (data) {
let tempArray =[];
for(var i=0; i<data.length; i++) {
tempArray .push({ label: data[i].Country, value: data[i].Country});
}
this.items = tempArray
this.error = undefined;
} else if (error) {
this.error = error;
this.contacts = undefined;
}
}
check Fetching and Displaying Picklist Values In Lightning Web Components (LWC) : (https://www.salesforcepoint.com/2020/07/picklist-values-in-LWC-Withoutdefault-recordtypeid.html)
All Answers
@wire(ConList)
wiredContacts({ error, data }) {
if (data) {
let tempArray =[];
for(var i=0; i<data.length; i++) {
tempArray .push({ label: data[i].Country, value: data[i].Country});
}
this.items = tempArray
this.error = undefined;
} else if (error) {
this.error = error;
this.contacts = undefined;
}
}
check Fetching and Displaying Picklist Values In Lightning Web Components (LWC) : (https://www.salesforcepoint.com/2020/07/picklist-values-in-LWC-Withoutdefault-recordtypeid.html)
when onchanged apply. here country is the selected country of combobox.