如何使用chrome中的chrome.storage.local.get设置变量

时间:2015-05-04 10:05:41

标签: javascript google-chrome-extension

var dataset = [
    {
        label: "ARBAAZ",
        data: [[348854000, 500.00]],//created from [bidticks,bidamt]
        color: "#FF0000",
        points: { fillColor: "#FF0000", show: true },
        lines: { show: true }
    },
    {
        label: "SHEKHAR",
        data: [[348845000, 600.00], [48838000, 800.00]],
        color: "#0062E3",
        points: { fillColor: "#0062E3", show: true },
        lines: { show: true }
    }
];

我想将var curline; chrome.storage.local.get("value",function(item) { window.curline=item["value"]; }); alert(curline); 设为curline,此代码位于item["value"],谢谢。

1 个答案:

答案 0 :(得分:1)

chrome.storage API is asynchronous。回调将在稍后执行, 后发出警告。

这意味着您必须在通过的回调中提醒结果:

var curline;
chrome.storage.local.get("value",function(item)
{
    window.curline=item["value"];
    alert(curline);
    // here you may use curline, or pass it as argument to other functions 
});