当我拨打store.put(game)
时,我有一个名为的巨大数组,该选项卡变成白色,并在chrome任务管理器中消失。基本上,过程只是停止和它未能存储阵列将大量字符串存储到IndexedDB中
var trans = this.db.transaction('Games', 'readwrite');
var store = trans.objectStore('Games');
store.get(new Date().toLocaleDateString() + ' ' + prize.value).onsuccess = function() {
var game = this.result;
game.combs = game.combs.concat(newCombs); //I'm appending to the game.combs array which is empty when I first run it (when it also crashes)
store.put(game);
}
trans.oncomplete = function(evt) {
arrLength = 0;
newCombs = [];
}
这就是game
等于:
game = {
name: new Date().toLocaleDateString() + ' ' + prize.value,
date: new Date().toLocaleDateString(),
prize: prize.value,
playerData: [...],
points: {...}
}
上面部分是一个对象的方法,以便this
不是窗口对象一切工作正常,直到代码命中:store.put(game);
页面刚刚崩溃。
你确定'this'是你认为它是? 'this'不会保留在匿名函数中,而是在'onsuccess'事件处理函数中的一个匿名函数中使用它。你有没有尝试记录'游戏'变量? – paldepind 2015-02-12 07:34:09
@paldepind'this'在它正确的上下文中工作正常我得到正确的'游戏'对象。阅读评论(以防万一你得到这个问题)在底部我想出了我的问题,我不想复制粘贴在这里。 – 2015-02-12 19:41:14