나를 멍청한 놈 전화 그러나 나는이 작업을 얻이 수없는 것 :크롬 storage.get 범위 문제
var value = ""; // Tried this
function getKey(key) {
var value = ""; // And this
chrome.storage.local.get(key, function (data) {
var value = data[key];
console.log(value); // This prints the correct value
});
console.log(value); // But this will always print null
}
어떤 생각을 왜?
방금 알아 냈습니다. 내가 동기로 작동하도록 할 수 있으면 좋겠어? 또는 적어도 getKey가 값을 반환하는지 확인하십시오. –
getKey를 비동기 적으로 호출해야합니다. 선언을 getKey (key, callback)로 변경하고 "value"를 리턴하지 않고 콜백으로 전달하십시오. – rgeorgy