ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • localstorage 객체 값을 업데이트하고 jquery를 사용하여 저장
    카테고리 없음 2020. 8. 11. 01:29

    질문

    localstorage 객체 값을 업데이트하는 방법 & jquery를 사용하여 저장합니까?

    아래는 내가 시도한 코드입니다.

    var cachekey = "shop/elasticCache/sku$$" + this.product.parentSku
    const { category } = JSON.parse(
      localStorage.getItem("shop/elasticCache/sku$$" + this.product.parentSku)
    )
    var productcache = []
    productcache = localStorage.getItem(cachekey)
    var updatedproductcache = JSON.parse(productcache)
    updatedproductcache.name = category
    productcache = JSON.stringify(updatedproductcache)
    localStorage.setItem(cachekey, productcache)
    

    localstorage json에서 category 데이터를 업데이트하려고합니다.


    답변1

    필요하지 않은 코드 (반복 코드)를 제거하면

    const cachekey = "shop/elasticCache/sku$$" + this.product.parentSku,
      {category} = JSON.parse(localStorage.getItem(cachekey));
    category.name = category;
    localStorage.setItem(cachekey, JSON.stringify(category));

    말이 안 되더라도 제대로 작동해야하며 typeof category! == "undefined"를 확인해야합니다. 아직 localStorage에 존재하지 않을 수 있습니다.



     

     

     

     

    출처 : https://stackoverflow.com/questions/63241532/update-localstorage-object-value-save-it-using-jquery

    댓글

Designed by Tistory.