【发布时间】:2015-08-24 04:18:57
【问题描述】:
使用 jquery,我正在尝试使用 json 填充选择下拉列表。我正在尝试从下面的 json 中显示国家/地区列表...
{
"country":[
{
"China":[
{
"tarrifType":"Pay as you go"
},
{
"fixLine":"23p"
}
],
"India":[
{
"sms":"39p"
},
{
"fixLine":"3p",
"sms":"59p"
}
],
"Poland":[
{
"mobile":"29p",
"sms":"19p"
},
{
"tarrifType":"China Pass",
"fixLine":"23p"
}
]
}
]
}
到目前为止,我尝试使用的 jquery 如下...
$.getJSON("js/widgets/country-picker.json", function(result){
$.each(result, function(i, field) {
$('#js-rate-select').append($('<option>').text(field[1]).attr('value', field[1]));
});
});
但它不会填充选择下拉菜单或给出任何 DOM 错误。有什么建议我可以解决这个问题吗?我认为问题在于 json 格式 - 我可以更改谢谢
【问题讨论】:
-
你真正想要选择的json的哪一部分?国家名称或每个国家的一部分?