我需要阅读一个递增的 XML 文件。因此,使用递归函数我将最新的值传递index
给.slice().each
但由于某些原因再次调用该函数时它完全停止。怎么了?为什么它不切片到下一个指定的索引?我的代码有什么问题?
function processXML(indexValue) {
var tocURL = "../broadcasted.xml";
$.get(tocURL, function(d) {
var length = $(d).find('tweet').length;
var count = indexValue;
$(d).find('tweet').slice(count).each(function(index) {
var cvdIndexId = $(this).find("index");
var cvdTweetAuthor = $(this).find("author").text();
var cvdTweetDescription = $(this).find("description").text();
setTimeout(function() {
if (index == (length - 1)) {
processXML(index + 1);
//alert(index+1);
} else if (cvdTweetAuthor === "Animator") {
$('#cvd_bubble_left').html('');
obj = $('#cvd_bubble_left').append(makeCvdBubbleAnimator(cvdIndexId, cvdTweetAuthor, cvdTweetDescription));
obj.fitText(7.4);
$('#cvd_bubble_right').html('');
} else {
$('#cvd_bubble_right').html('');
obj = $('#cvd_bubble_right').append(makeCvdBubble(cvdIndexId, cvdTweetAuthor, cvdTweetDescription));
obj.fitText(7.4);
$('#cvd_bubble_left').html('');
}
}, index * 1000);
});
});
}
<?xml version="1.0" encoding="UTF-8"?>
<root bubbles="7">
<tweet broadcasted="bubble">
<author><![CDATA[@Liciiious]]></author>
<description><![CDATA[#EveryoneLovesBeinsport (cc @beinsport @charlesbietry). #pureLIVE]]></description>
<index>1</index>
</tweet>
<tweet broadcasted="bubble">
<description><![CDATA[Message]]></description>
<author><![CDATA[beIN Sport]]></author>
<index>2</index>
</tweet>
<tweet broadcasted="bubble">
<author><![CDATA[@Liciiious2]]></author>
<description><![CDATA[#EveryoneLovesBeinsport (cc @beinsport @charlesbietry). #pureLIVE]]></description>
<index>3</index>
</tweet>
<tweet broadcasted="bubble">
<description><![CDATA[Message]]></description>
<author><![CDATA[Animator]]></author>
<index>4</index>
</tweet>
<tweet broadcasted="bubble">
<author><![CDATA[@MAuricious]]></author>
<description><![CDATA[#EveryoneLovesBeinsport (cc @beinsport @charlesbietry). #pureLIVE]]></description>
<index>5</index>
</tweet>
<tweet broadcasted="bubble">
<description><![CDATA[Message]]></description>
<author><![CDATA[beIN Sport]]></author>
<index>6</index>
</tweet>
<tweet broadcasted="bubble">
<description><![CDATA[Messagexxx]]></description>
<author><![CDATA[beIN Sportxxx]]></author>
<index>7</index>
</tweet>
<tweet broadcasted="bubble">
<description><![CDATA[Messagexxxzzzz]]></description>
<author><![CDATA[beIN Sportxxxzzzz]]></author>
<index>8</index>
</tweet>
</root>