我有一个 JSON 对象 (activityItem),我将它添加到数组列表 (activityArrayList) 中。
var activityArrayList = [];
变量活动项 = {
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); 函数显示列表中正确的项目数(数组大小),但项目详细信息都相同,它们是最后添加到列表的项目的详细信息。
列表中添加了 2 个不同的 Activity 项,但它显示了两次添加的最后一项的详细信息。