There is a list of news article in a page. Everytime user clicks on it, it saves news id and title to localstorage. My code is replacing localstorage data everytime I click new item.
How do I append new data into localStorage ?
Setting localStorage
awardForArticleRead: function(latestNews){
var articleData = {};
articleData['newsId'] = latestNews.news_id;
articleData['newsTitle'] = latestNews.title;
localStorage.setItem("articleRead", JSON.stringify(articleData));
},
calling function while it goes to detail page
newsDetail: function(key, id) {
var _this=this;
newsDetail = API_DATA['getLatestNews'][key];
myApp.mainView.loadPage('news1.html');
myApp.onPageInit("news_detail", function(page){
_this.awardForArticleRead(newsDetail);
_this.showNewsDetails(newsDetail);
})
},