0
I am making a To from the List using MVC, I have an array that saves the tasks added by the user and from this array I create elements in DOM. Can I reference the specific item of the array from a click on the DOM? For example, how can I delete an item from the list when its DOM element is deleted? I tried the code below, using ${task} to pass the object I want to change, but it doesn’t work because the element is no longer a reference to the object. Is there any other way to change the specific object?
return array.lista.map(tarefa => {
return `<button onclick='controller.conclui(event, ${tarefa})'></button>`
}).join('');
Edit. I understand, I would have to pass an indenter to get a reference to the object I want to edit, but would there be any way to get a direct reference? as is possible with React, for example:
{tarefas.map(tarefa => (
<button
type="button"
onClick={event => onButtonClick(event, tarefa)}
key={tarefa}
>
{tarefa.classe}
</button>
))}
because in this case I can access the properties of my 'task' object directly, but I don’t know if it has to achieve this effect with pure js
This answers your question? You can get Event.preventDefault() if the call has parameters?
– Luiz Felipe