如何获取chrome storage sync get之外的内容 [英] How do I get content outside of chrome storage sync get
本文介绍了如何获取chrome storage sync get之外的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function ff_search_profile_details(login) //login optional
{
var storage = "user_prf_dtls";
chrome.storage.sync.get({ storage }, function (data) {
var dtls = data.storage;
if (dtls) {
dtls = JSON.parse(dtls);
dtls[login];
alert(dtls[login]); // here getting properly
}
});
alert(dtls[login]); // here required but not getting
}
我尝试过:
What I have tried:
function ff_search_profile_details(login) //login optional
{
var storage = "user_prf_dtls";
chrome.storage.sync.get({ storage }, function (data) {
var dtls = data.storage;
if (dtls) {
dtls = JSON.parse(dtls);
dtls[login];
alert(dtls[login]); // here getting properly
}
});
alert(dtls[login]); // here required but not getting
}
推荐答案
var dtls; // define the variable outside of the function
function ff_search_profile_details(login) //login optional
{
var storage = "user_prf_dtls";
chrome.storage.sync.get({ storage }, function (data) {
dtls = data.storage;
if (dtls) {
dtls = JSON.parse(dtls);
dtls[login];
alert(dtls[login]); // here getting properly
}
alert(dtls[login]); // should now be able to use dtls anywhere
这篇关于如何获取chrome storage sync get之外的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文