Answer the question
In order to leave comments, you need to log in
How to get element id (variable i)?
Subject.
You need to somehow determine by the onCLick function which element the delete icon (span) belongs to in order to form a request to localStorage.
if(localStorage.length == 0)return(notesTemplate = <div>Заметки пусты </div> );
else{
for(var i = 0; i < localStorage.length; i++){
var readObj = JSON.parse(localStorage.getItem("Note " + i));
notesTemplate.push(
<div key = {i} className="wrap">
<div
className={readObj.isComplete + ' note'}
onClick={self.changeStateOfComplete}>
{readObj.note}
</div>
<span onClick={self.deleteNote} className={"close"}>X</span> // вот это место
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
I'd do it with the data-* attribute, but there was some discussion in this answer , so take your pick.
..
deleteNote(e) {
console.log(e.target.dataset.item) //здесь будет идентификатор элемента
}
...
<span onClick={self.deleteNote} data-item={i} className={"close"}>X</span>
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question