ユーザーがゲームループを完了するか新しいゲームを開始するときにすべてのローカルストレージをクリアしようとしていますが、同じ関数内でclear()を使用しながらlocalStorageオブジェクトを保持する
私はボリュームのための私の音値で、すでにこれを行うことができます。
// inside a conditional statement that fires when the user chooses to start a new game.
if (newGameBool === '1') {
var tst = myAu;
//myAu is the stored value that the user sets as sound using a range type input
localStorage.clear();
localStorage.setItem("Au", tst);//A newly cleared localStorage just got a new value, and it's the same as it was before.
UI.myLoad();//reload the function that uses LS to do things.
}
は、私は彼らに添付反復番号を持っているキーのためにこれをどのように行うのですか?ここで
は、私はそれらを保存する方法である:
私はサウンド機能を行った方法それらを呼び出すvar i = +v + +1;
localStorage.setItem("v", i);
var vv = localStorage.getItem("v");
localStorage.setItem("LdrBrd_" + vv, JSON.stringify(LdrBrd));//saves all data with the iterating key name.
:
var gv = v + 1;//v calls the value from LS and adjusted for off-by-one error. gv is a local variable.
if (newGameBool === '1') {
var ldd, vg;
for (var ii = 0; ii < gv; ii++) {
var ld = localStorage.getItem("LdrBrd_" + ii);
if (ld != null) {
//these are the values that i want to pass beyond the clear point
ldd = JSON.parse(ld);//JSON string of data saved
vg = ii;//how many of them.
}
}
localStorage.clear();
for (var xx = 0; xx < vg; xx++) {
var nld = localStorage.getItem("LdrBrd_" + xx);
if (nld != null) {
localStorage.setItem("LdrBrd_" + ii, JSON.stringify(ldd));
}
}
localStorage.setItem("v", vg);
UI.myLoad();
}
私が何を参照するために、様々なスポットにはconsole.log()を使用しています続行中です。私は、値が間違っていて、すべてをすべて保存していないかどうかを確認するためにクリア関数をコメントアウトします。私はフィドルを作ろうとしましたが、ローカルストレージはそこでは全く動作していませんでした。ビジュアルスタジオではうまくいきますが、このファイルへのスクリプトはほとんど2000行ですので、私はそれをどのように知っていたかを最高のものにするようにしました。
ご協力いただきありがとうございます。
は、なぜあなたはそれを完全にクリアされている削除ではなく、保存された(下記参照)好きな方法でより多くの項目がある場合は、このオプションがベストです削除したいデータを削除するだけですか? –
私は他のものをすべてクリアしたいので、削除したいアイテムが約20ほどあり、クリアポイントを超えてgamestateに保存して渡したいものがほんのわずかです – MrEhawk82