0
我想增加我的localStorage值每次在if語句中的條件是真的,但似乎我不能做到這一點。嘗試了一切可能。這是我的代碼,執行檢查並增加值。不能增加一個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插件。我正在嘗試增加在我的函數中作爲參數String傳遞的probSolKey。每當條件滿足時,我嘗試將自身增加1.我不知道如何正確實現。任何人都可以幫我解決這個問題,真的很感激!
做一些調試,我發現這一點:
console.log(this.storage.get(probSolKey));
拋出「南」的怪異值。
不行,它不起作用。 ( 當我做console.log(「計數器」+ this.storage.get(probSolKey)) 它提供計數器NaN作爲輸出,並且不會增加值任何想法? – Htlcs
你可以做一個console.log(這.storage.get(probSolKey)並告訴我們你得到了什麼? – user3417400
當然,console.log(this.storage.get(probSolKey))會拋出一個怪異的「NaN」值,我不知道這是什麼意思! – Htlcs