【发布时间】:2014-08-02 19:59:05
【问题描述】:
我正在尝试使用 each 循环一个接一个地获取多个乐队名称,但我得到的只是循环中的最终名称。谁能告诉我我做错了什么。
XML 结构:
<resultsPage>
<results>
<event type="concert">
<performance displayName="bandname1"></performance>
<performance displayName="bandname2"></performance>
<performance displayName="bandname3"></performance>
</event>
</results>
</resultsPage>
ajax:
$.ajax({
url: 'xml/timeline.xml',
dataType: 'xml',
success: function(data){
$(data).find('resultsPage results event').each(function(){
var type = $(this).attr('type');
var band = $(this).find('performance artist').each(function(){
name = $(this).attr('displayName');
})
$('.timeline ul').append(
'<li>A '+type+' played by '+name+'</li>'
);
});
},
error: function(){
$('.timeline').text('Failed to get feed');
}
});
【问题讨论】:
标签: jquery ajax xml loops each