【发布时间】:2020-12-14 12:52:21
【问题描述】:
使用我当前的代码,我的本地存储中有我添加的项目,但它只显示我的购物篮中的一个
我不知道如何解决我的问题,你有什么想法吗?
function displayPanier(product) {
function getTeddies() {
let teddiesPanier = JSON.parse(localStorage.getItem("basketProducts"));
return teddiesPanier;
}
let teddiesPanier = getTeddies();
//faire une boucle pour iterrer sur les produits dans le local storage
function panierTeddies (){
const panierStorage = document.getElementById("test")
panierStorage.innerHTML = `
<table class="table bg-light">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Photo</th>
<th scope="col">Nom</th>
<th scope="col">Prix</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td><img id=panierImg class="img-fluid" src="${teddiesPanier[0].imageUrl}" style="max-width: 40px;"></td>
<td><h5 class="font card-title">${teddiesPanier[0].name}</h5></td>
<td><p class="card-text prix">${teddiesPanier[0].price / 100}€</p></td>
</tr>
</tbody>
</table>
<td><button onclick="removeProduct('${product}')" class="btn btn-primary">Supprimer</button></td>
`
}
console.table(teddiesPanier)
panierTeddies();
}
【问题讨论】:
-
描述你的上下文,也尝试添加一些调试代码并显示控制台输出,告诉我们你尝试了什么......
标签: javascript local-storage innerhtml