【发布时间】:2010-11-05 12:18:57
【问题描述】:
如果我正在循环访问 JSON 调用的结果,我如何知道我是否处于第一次迭代中?
在此示例中,我创建了 loopIndex 变量来指示我要查找的内容 - 但它实际上并未设置在任何地方。
您如何知道您在循环中的哪个位置 - 您正在进行哪个迭代?
$.getJSON(myurl, function(data) {
$.each(data.results, function() {
// what's the index of this iteration?
if(loopIndex==0){
console.log("first iteration!");
}
});
});
【问题讨论】:
-
阅读文档可以创造奇迹。 :)