从chrome.storage.local获取原始值

时间:2015-03-03 15:03:02

标签: javascript google-chrome-extension google-chrome-storage

基本上,我想将一个存储的原语设置为jQuery UI Tab设置的值:

$("#tabs").tabs({
    active: chrome.storage.local.get("idx", function(obj){ 
                console.log(obj["idx"])}); // returns primitive integer I want. 
            }), ...  
}); 

标准的chrome-storage-get协议非常复杂,我不确定如何将对象属性值本身设置为active:的值而不是对象。

active: 3 // chrome.storage.local.get("idx")

有什么办法吗?

1 个答案:

答案 0 :(得分:2)

chrome.storage是异步的,因此您的代码看起来更像是这样:

chrome.storage.local.get("idx", function(obj) {
  $("#tabs").tabs({
    active: obj.idx  
  });
});
相关问题