I have an Ionic Storage DB with the following key/value pair:
Key: settingsJSON
Value: {toggleDates: false, toggleIndicator: false, toggleRepayments: false}
Is there any way to update part of the object (i.e set toggleDates
to true
) without overriding the rest of object stored in the value?
I've tried:
let settingsTemp = JSON.stringify({toggleDates: true});
this.storage.set('settingsJSON', settingsTemp)
But this updates the entire object to {toggleDates: true}
.
I've also tried:
this.storage.set('settingsJSON.toggleDates', true)
But this just creates a new key/value named settingsJSON.toggleDates
.
What about something like this:
// Get the entire data
this.storage.get('settingsJSON').then(valueStr => {
let value = valueStr ? JSON.parse(valueStr) : {};
// Modify just that property
value.toggleDates = true;
// Save the entire data again
this.storage.set('settingsJSON', JSON.stringify(value));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With