我从我的API中获取了一些我希望迭代并添加到div的数据,以下是我的API中的JSON数据:
{
"programmes":{
"outline":"This is a listing of all programmes on sky.",
"programme":[
{
"@id":"1",
"name":"Programme 1",
"img-path":"img/default.png",
"moods":{
"mood":[
"Scared",
"Sad"
]
}
},
{
"@id":"2",
"name":"Programme 2",
"img-path":"img/default.png",
"moods":{
"mood":[
"Happy",
"Wide-Awake"
]
}
}
]
}
}
这是我的JS:
$.ajax({
type: "GET",
url: "http://127.0.0.1:5000/data",
data: { get_param: 'value' },
dataType: "json",
success: function(data){
$.each(data.programmes.programme, function(index, element){
console.log(element);
$("#programmes").append('\
<div class="col col-md-2">\
<div class="img-element">\
<img src="img/app.jpg" />\
</div>\
<div class="text-element">\
\
</div> \
</div>\
');
});
}
});
这是我在运行网页时在控制台中获得的内容:
它逐行打印而不是打印对象。我在哪里错了?