如何从服务工作者更新IndexedDB中的对象

时间:2017-05-28 21:16:45

标签: javascript indexeddb service-worker

我试图从Service Worker更新IndexedDB中的Object Store,这是我现在的代码:

function updateUrlLink(url_link) {
  var request = indexedDB.open('db', 1);
  var url_link_value = url_link;

  request.onsuccess = function (event) {  
    var store = request.result.transaction("url_link", "readwrite").objectStore("url_link");
    store.add(url_link_value, "url_link");
  };

  request.onupgradeneeded = function (event) {
    var db = event.target.result;
    var store = db.createObjectStore('url_link');
  };

}

这是更新url_link的正确方法还是其他方式?

0 个答案:

没有答案