-9

私は次のような配列を持っています

countries: [{
      "name": "Afghanistan",
      "cca2": "AF",
      "calling-code": "93"
    },
    //{"name":"Åland Islands","cca2":"AX","calling-code":"358"},
    {
      "name": "Albania",
      "cca2": "AL",
      "calling-code": "355"
    }, {
      "name": "Algeria",
      "cca2": "DZ",
      "calling-code": "213"
    }, {
      "name": "American Samoa",
      "cca2": "AS",
      "calling-code": "1684"
    }, {
      "name": "Andorra",
      "cca2": "AD",
      "calling-code": "376"
    }, {
      "name": "Angola",
      "cca2": "AO",
      "calling-code": "244"
    }, {
      "name": "Anguilla",
      "cca2": "AI",
      "calling-code": "1264"
    }, {
      "name": "Antigua and Barbuda",
      "cca2": "AG",
      "calling-code": "1268"
    }
     ]

このリストを反復処理して、次のような選択リストを作成したい

<select>
   <option value="AF">Afganisthan</option>
   ....
<select>

これは私がしました

for (var i = 0; i < countries.length; i++) {
    out += "<option value='" + countries[i].cca2 + "'>" + countries[i].name + "</option>";
}

しかし、何も表示されません..

4

5 に答える 5