我有以下代码,它从 json 请求中获取名称和值的数组,并将它们附加到 html 页面中的选择项。
到目前为止,它在除 IE 之外的所有浏览器中都适用于我,而不是预期的结果
<option value="211">Bakery and Cafe</option>
我得到一个结果
<option value="211"/>
Javascript:
$.getJSON(link,function(data) {
$('#CltOrgType').find('option').remove().end();
for (key in data){
alert(data[key][0],data[key][1]);
var option = new Option(data[key][0],data[key][1],false,false);
$('#CltOrgType').append(option);
}
});
JSON 响应如下所示
[[ "Asian Cuisine" , "200" ], [ "Bakery and Cafe" , "211" ], [ "Breakfast, Lunch & Snacks" , "215" ], [ "Cafe" , "195" ], [ "Fully Licensed Restuarant" , "205" ], [ "Japanese Cuisine" , "210" ], [ "Licensed Italian Cuisine" , "206" ], [ "Middle Eastern Cuisine" , "209" ], [ "Pizza Restaurant" , "199" ], [ "Salads, Soups & Sandwiches" , "213" ], [ "Sandwiches and Wraps" , "207" ], [ "Sushi" , "214" ], [ "Take Away" , "208" ], [ "Yoghurt and Salads" , "212" ]]
并且所有浏览器都使用 console.log(data[key][0] +","+data[key][1]) 或 alert(data[key][0] +","+data[key ][1])
任何想法、解决方案或想法将不胜感激!因为这个让我卡了一段时间