[TIL] 02.03
2020. 2. 4. 00:25ㆍTIL
장바구니에 들어갈 값들을 localStorage에 저장을 하여 불러 오는 방식을 사용하여 구현 하였다 .
추가하는 코드 (중복 방지)
let oldStorage:any = localStorage.getItem('items')
let newSrotage:any = []
if(oldStorage){
newSrotage = JSON.parse(oldStorage)
for(let i = 0; i < newSrotage.length; i++){
if(!newSrotage[i][name]){
localStorage.setItem("items", JSON.stringify(newSrotage.concat(obj)))
}
}
}
localStorage.setItem("items", JSON.stringify(newSrotage.concat(obj)))
삭제 코드
let oldStorage:any = localStorage.getItem('items')
let newSrotage:any = []
setchecked(false)
newSrotage = JSON.parse(oldStorage)
newSrotage = newSrotage.filter((val:any) => !val[name])
localStorage.setItem("items", JSON.stringify(newSrotage))
'TIL' 카테고리의 다른 글
[TIL] 02.05 typescript 수정 (0) | 2020.02.05 |
---|---|
[TIL] 02.04 과제 제출!! (0) | 2020.02.04 |
[TIL] 02.02 (0) | 2020.02.02 |
[TIL] 02.01 (0) | 2020.02.01 |
[TIL] 01.31 (0) | 2020.01.31 |