0

localStorage には、オブジェクト レコードがあります。多くのフィールド records[recordId] があり、これらのエントリを削除できるようにしたいと考えています。以下は私の削除機能ですが、機能しません。すべてのレコードは、ローカル ストレージ内のレコード オブジェクトに関連付けられたままになります。正しい方法で削除しているため、何が問題なのかわかりません。レコードオブジェクトを印刷すると、すべてのレコードがキーとともにまだそこにあります????

function deleteLocalRecord(recordId) {
     var records = localStorage.getItem('records');
     var theRecords;
     if (supports_html5_storage()) {

          if (records == null) {
            theRecords = {};
          } else {
            // parse the records
            theRecords = JSON.parse(records);
          }

          theRecords[recordId] = '';  // set the record to empty string.
          delete theRecords[recordId]; // delete the record

          // reset the records object in local storage after change
          localStorage.setItem('records', JSON.stringify(theRecords));

     }
  }

  function supports_html5_storage() 
  {
    try 
    {
        return 'localStorage' in window && window['localStorage'] !== null;
    } 
    catch (e) 
    {
        return false;
    }
   }
4

1 に答える 1