function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
himanshu Soni 31himanshu Soni 31 

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>
Best Answer chosen by himanshu Soni 31
Venu9999Venu9999
Change wiredContacts code    

 @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

Venu9999Venu9999
Change wiredContacts code    

 @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)
This was selected as the best answer
himanshu Soni 31himanshu Soni 31
sir how can i set country to apex controller like( req.setEndpoint('https://api.covid19api.com/total/country/' +country );
when onchanged apply. here country is the selected country of combobox.