Fill HTML dropdown box with external JSON file data

后端 未结 4 538
甜味超标
甜味超标 2021-01-27 21:28

I am trying to fill a HTML Dropdown menu with data from an external JSON file, which contains the following

{
    \"Destinations\": [
    {
        \"destinatio         


        
4条回答
  •  耶瑟儿~
    2021-01-27 21:47

    Consider you have got the response from server like

    {
        "Destinations": [
        {
            "destinationName": "London",
            "destinationID": "lon"
        },
        {
            "destinationName": "New York",
            "destinationID": "nyc"
        },
        {
            "destinationName": "Paris",
            "destinationID": "par"
        },
        {
            "destinationName": "Rome",
            "destinationID": "rom"
        }
        ]
    }
    

    Then your next step should be iteration of that json

    $.each(data.Destinations, function(key, val) {
        items.append('');
      });
    

    YOu can see the demo here Fiddle Demo

提交回复
热议问题