インクリメントされた 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>