到达数据对象末尾时停止迭代 [英] Stop iteration when end of data objects are reached
本文介绍了到达数据对象末尾时停止迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 TweenMax 库,当到达数据对象的末尾而不是循环时,我无法杀死或停止delayedCall
,因为它是自调用函数.
Using the TweenMax library, I am unable to kill or stop a delayedCall
when the end of the data object is reached instead of looping because it is a self calling function.
https://jsfiddle.net/rdzo13cf/6/
在上面的示例中,数据的最后一项没有显示.
In the example above the last item in the data is not displayed.
推荐答案
实际上是因为您在设置iter
变量之前先对其进行了递增.这会导致它不显示最后一项,而您要在之后增加:
Actually it's because you are incrementing your iter
variable before you set it. Which causes it to not display the last item, you want to increment after:
function setContent() {
element.html(data[iter].content);
iter = iter >= data.length-1 ? -1 : iter;
iter = iter + 1;
}
基本上,当您要遍历[0,1,2]
时,您正在遍历索引[1,2,3]
.
Basically you are going over indexes [1,2,3]
when you want to be going over [0,1,2]
.
这篇关于到达数据对象末尾时停止迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文