无法增加localStorage值

时间:2014-03-28 18:25:54

标签: javascript html5 local-storage impactjs

每次if语句中的条件为true时,我都会尝试递增localStorage值,但似乎我无法正确执行。尝试了一切可能。这是我的代码,它执行检查并增加值。

for(var j = 0; j < inputArray.length; j++){
    for(var k = 0; k < this.probsSolved.length; k++){
        if(inputArray[k] == this.probsSolved[j] ){

            //increment the localStorage value here

            **this.storage.set(probSolKey,parseInt(this.storage.get(probSolKey)) + 1);**

            if(this.storage.get(probSolKey) >= totalProbToSolve){
                this.storage.set(achkey,1);
                this.triggerAchievements(id,name);
                return;
            }
        }
    }
}

所以我使用了ImpactJS引擎的localStorage插件。我试图增加probSolKey,我将我的函数作为参数String传递。每当条件满足时,我尝试将自己递增1.我不知道如何正确实现这一点。有人帮我解决这个问题,真的很感激!

做一些调试我发现了这个:

console.log(this.storage.get(probSolKey));

抛出一个奇怪的“NaN”值。

1 个答案:

答案 0 :(得分:0)

当您存储了您尝试增加的属性值时,您认为存储了一个数字,但实际上并没有。

您存储的值是一个数字,因此它被转换为一个,但转换失败,因为该值无法解析为数字。

NaN代表的是什么,不是数字,不能被解析为数字。

相关问题