【发布时间】:2014-07-26 10:30:17
【问题描述】:
我想动态生成列表条目,同时将它们作为 jsonstore 文档添加到我的本地存储中。
当我这样做时:
var j=0;
while(j<7) {
/* populating our jsonstore */
accessor.add({stuff_to_add})
.then(function(){})
/* showing it to the user */
$('<li>').attr({attributes}).html('html').appendTo('element');
j++;
}
只有一个文档被添加,因为我认为 worklight 不会自动将添加请求放入队列中,并且如果前一个未解决或类似这些问题,则取消最后一个。
所以当我这样做时:
var j=0;
while(j<7) {
/* populating our jsonstore */
accessor.add({stuff_to_add})
.then(function(){
/* showing it to the user */
$('<li>').attr({attributes}).html('html').appendTo('element');
j++; })
}
Mozilla 完全崩溃,甚至没有成功停止脚本我不明白为什么,因为它应该只调用 add 函数多次 = (调用时间 (accessor.add) / time to loop) 这应该是有限。
编辑:实际上,如果我们假设 worklight 没有将文档放入添加队列中,则每次循环循环时都会替换初始添加请求,并且它永远不会完成,这就解释了崩溃。
编辑 2:尝试使用递归函数调用自身,直到 j 达到 7 而不是循环
【问题讨论】:
标签: javascript ibm-mobilefirst jsonstore