javascript - localstorage.getItem 只显示一个数据,尽管数组中有多个数据
问题描述
尽管数组项数组中存储了多个数据,但它仅显示最近添加的数据。这可能是什么原因?预先感谢您对我们的支持
// List items
const array_item = JSON.parse(localStorage.getItem("array_item") || "[]");
array_item.forEach(function(item,index,array){
const output = '<div class="bg-card p-2" style="font-size:14px;"><div class="container"><strong>Okunmadı olarak işaretlediğin makale:</strong> <a href="<?=PROOT?>home/details/'+item.sef_link +'">'+item.title+'</a></div></div>';
console.log(array);
document.getElementById("mark").innerHTML = output;
});
解决方案
const array_item = JSON.parse(localStorage.getItem("array_item") || "[]");
array_item.forEach(function(item,index,array){
const output = '<div class="bg-card p-2" style="font-size:14px;"><div class="container"><strong>Okunmadı olarak işaretlediğin makale:</strong> <a href="<?=PROOT?>home/details/'+item.sef_link +'">'+item.title+'</a></div></div>';
console.log(array);
document.getElementById("mark").innerHTML += output;
});
推荐阅读
- python - 如何在 PyGame 中创建一个矩形作为精灵
- python - 如何获取 Android 上的窗口位置或键盘高度?
- android - 水平放置菜单项
- apache-spark - 如何使用 GCP 实例访问 Spark Web UI?
- android - Android Q 保存的媒体文件未显示在图库中
- c++ - 在 CentOS 8 中安装较旧的 gcc/g++ 版本
- jquery - jQuery 输入框自动添加 DOT 为 Currency 格式并且只允许数字
- react-native - 按钮在 MapView 标注 React Native 中不起作用
- c++ - 尝试计算 pi 时不断得到 0
- scala - lmcoursier.internal.shaded.coursier.error.FetchError$DownloadingArtifacts: Error fetching artifacts: 是什么意思?