peet86 / cart-localstorage

JavaScript Shopping Cart library on top of localStorage
https://peet86.github.io/cart-localstorage/
MIT License
91 stars 18 forks source link

Updating line item nested objects #20

Open owldesign opened 3 years ago

owldesign commented 3 years ago

When I use the update() is there a way to target nested objects?

For example, here is my line item object:

{
     id: 4133
     nonprofit: {
          name: "Product 1",
          message: "message for someone",
     }
     price: 10
     quantity: 1
}

I wanted to use the update() to change the message within the nonprofit object.

Right now the update() only takes "field" key but how can I access that field within the nested object?

I tried doing this but it just add it as a key within the object update(4133, 'nonprofit.message', 10)

Thanks!

peet86 commented 3 years ago

Unfortunately right now deep updates are not possible. Thanks for the suggestion though, I will implement this.