我请求的 JSON 是数组中的一个数组(我认为),看起来像这样:
"results": {
"collection1": [
{
"Inches": "1\"",
"Resort": "Keystone",
"index": 1,
"url": "http://extras.denverpost.com/skireport/colorado/recentsnow.html"
},
{
"Inches": "0\"",
"Resort": "Breckenridge",
"index": 2,
"url": "http://extras.denverpost.com/skireport/colorado/recentsnow.html"
},
{
"Inches": "0\"",
"Resort": "Telluride",
"index": 3,
"url": "http://extras.denverpost.com/skireport/colorado/recentsnow.html"
},
我试图在列表中显示此信息,但我得到一个带有以下 JQuery 的“未定义”结果列表:
$.ajax({
url:"www.kimonolabs.com/api/5qtdkod0apikey=z6vewKq5SXBcF6Q6L17sQEJ8gaYMou0C",
crossDomain: true,
dataType: "jsonp",
'success': function (response) {
$(".panel-heading").html(response.name);
//Puts the API name into the panel heading
var collection = response.results.collection1;
for (var i = 0; i < collection.length; i++){
$(".list-group").append('<li class="list-group-item">' +
collection[i].resort.inches + '</li>');
//when I just try to bring in either resort or inches I get an 'undefined' list-- when I try to add both (e.g resort.inches) I don't get any results
}
}
});
定义度假村和英寸数据并将其显示在“list-group-item”列表中的最佳方法是什么。这是一个小提琴:http: //jsfiddle.net/6w0sdctg/