我有一个JSON对象(activityItem),我将其添加到数组列表(activityArrayList)中。
var activityArrayList = [];
var activityItem = {
activity_id: "" , activity_name: "", item_viewed_time: null, time_spent_on_item:0, like: "didn't like or dislike", };
我这样做是为了将活动项目列表添加到本地存储
activityArrayList.push(activityItem);
console.log(activityArrayList[0]);//see the item being added
localStorage['ActivityArrayList'] = JSON.stringify(activityArrayList);
var storedActivityList = (localStorage['ActivityArrayList']) ;
and in a new page in Jquery Mobile I have the following to retrieve the object
var retrievedStringList = localStorage.getItem(['ActivityArrayList']);
var convertedList = JSON.parse(retrievedStringList);
showitem(convertedList);
function showitem(ItemsList){
console.log(ItemsList);
}
console.log(ItemsList); function显示列表中正确的项目数(数组大小),但项目详细信息都相同,它们是要列出的最后添加项目的详细信息。
列表中添加了2个不同的活动项目,但它显示了最后添加两次的项目的详细信息。