Reputation: 95
I'm new to JSON & Chrome extension development. I have two HTML buttons namely 'Start' & 'Stop'. I have following JavaScript code:
var storage = chrome.storage.sync;
function setData(key, value) {
storage.set({ [key]: value });
}
function onClickMarkStartButton() {
var date = getCurrentDate();
var start = { 'start': getCurrentTime() };
setData(date, start);
}
function onClickMarkEndButton() {
var date = getCurrentDate();
var end = { 'end': getCurrentTime() };
setData(date, end);
}
It saves
6/1/2018 : {
"start":"16:34"
}
OR
6/1/2018 : {
"end":"16:40"
}
overwriting the previously saved key/value pair, instead of saving it like this
6/1/2018: {
"start": "16:34",
"end": "16:40"
}
Any suggestions?
Upvotes: 1
Views: 266
Reputation: 4817
Change your end function to this:
function onClickMarkEndButton() {
var date = getCurrentDate();
chrome.storage.sync.get(date, function (obj) {
setData(date, {
start: obj.start,
end: getCurrentTime()
});
});
}
Upvotes: 2