2013-02-04 69 views
0
var getShortenedUrl = function() { 

    chrome.tabs.getSelected(null, function (tab) { 

    var request_data = { 
     'command': 'generate', 
     'params': { 
     'url': tab.url, 
     'code': text_field.value 
     } 
    } 

    chrome.extension.sendRequest(request_data, function (data) { 
     switch (data.status) { 
     case 'OK': 
      setTextField(data.shortened_url) 
      bindBtnToCoopy() 
      chrome.storage.local.get(data.shortened_url, function (arr) { 
      if (!arr[data.shortened_url]) { 
       chrome.storage.local.set(
       {data.shortened_url: 
       tab.url}) /* <-- this thing throws an error */ 
      } 
      }) 
      break 
      /* ... */ 
     } 
    }) 
    }) 
} 

看到https://github.com/noformnocontent/git-io-chrome/blob/master/chrome/popup.js#L96Chrome扩展 “未捕获的SyntaxError:意外的标识” 关于`storageArea.set`


,如果我评论的chrome.storage.local.set一部分出来,一切都是 “完美”

+0

你的换行是冒险的。并使用分号! – Bergi

+1

[chrome.storage.local.set使用变量键名称]的可能重复(http://stackoverflow.com/questions/11692699/chrome-storage-local-set-using-a-variable-key-name) – pimvdb

+0

@pimvdb是的,它帮助!谢谢 –

回答

0

question @pimvdb提到,为了保存一个对象,我必须使用一个对象。

if (!arr[data.shortened_url]) { 
    var urlPair = {} 
    urlPair[data.shortened_url] = tab.url 
    chrome.storage.local.set(urlPair) 
} 

从那以后,我还发布了“Git.io Chrome浏览器”的v.0.5,看到http://git.io/crome更多

相关问题