Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

232
Views
how to custom output select2 ajax remote data

I want to create select2 with content flag, name country, and calling Codes. I have some problems with my code because I can't show the output what I want.

var countriesList = "https://restcountries.com/v2/all";




$.ajax({
  type: "GET",
  url: countriesList,
  dataType: "json",
  success: function (response) {
    $(".js-data-example-ajax").select2({
      data: response.map((e) => ({
        id: e.alpha2Code,
        text: e.name,
      })),
      width: 300,
      dropdownAutoWidth: true,
    });
  },
  error: function () {},
  complete: function () {},
});

from this enter image description here

to this enter image description here

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.