Skip to content

How to handle data that does not have id or text data fields #10

@cdesch

Description

@cdesch

How do I handle with select2 data that does not have id and text fields?

Data like this will work:

 var data = [
    {
      id: 0,
      text: 'enhancement'
    },
    {
      id: 1,
      text: 'bug'
    },
    {
      id: 2,
      text: 'duplicate'
    },
    {
      id: 3,
      text: 'invalid'
    },
    {
      id: 4,
      text: 'wontfix'
    }
  ];
  $('#request_for_proposal_geo_path_counties').select2({
    theme: "bootstrap",
    data:  data
  });

But data like this won't:

var data = [
   {
     "fips": "02",
     "name": "Alaska",
     "zip_codes": [],
     "counties": [],
     "population_0": 752680,
     "population_5": 698356,
     "population_18": 565916,
     "population_21": 534794
   },
   {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions