简体   繁体   English

重新加载扩展程序后,Chrome.storage.sync被覆盖

[英]Chrome.storage.sync get overwritten when extension reload

I have a chrome extension which creates context menus with data gotten from an array stored in the chrome.storage. 我有一个chrome扩展程序,它使用从chrome.storage中存储的数组获取的数据来创建上下文菜单。 This array is updated in the options.html page. 此数组在options.html页面中更新。

The context menu creator works fine, but when I open the options page and try to insert a new value into the array after reloading the extension it gets overwritten, losing the previous values. 上下文菜单创建器工作正常,但是当我打开选项页面并尝试在重新加载扩展名后将新值插入数组时,它会被覆盖,丢失先前的值。 ¿Is there any solution? 有什么解决方案吗? Edit 1 For clarification. 编辑1进行澄清。 The storage is kept, but when I try to push something into the array, it overwrites the whole array. 保留了存储空间,但是当我尝试将某些内容推入阵列时,它将覆盖整个阵列。

Edit2 编辑2
Options.html Options.html

function save_options() {
    var id = document.getElementById('id').value;
    ids.push(id);

    chrome.storage.sync.set({
        'movieId': ids
    }, function() {
        // Feedback
        var status = document.getElementById('status');
        status.textContent = 'Options saved.';
        setTimeout(function() {
            status.textContent = '';
        }, 750);
    });
    createRow(1);
}

That is the code I use to upgrading the array. 那就是我用来升级阵列的代码。

As @BenjaminGruenbaum said, I was doing var ids = [] erasing the previous stored data. 正如@BenjaminGruenbaum所说,我正在执行var ids = []擦除以前存储的数据。 Just by erasing it, the code worked. 只是通过擦除它,代码就起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM