Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge 31 #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Challenge 31 #2

wants to merge 6 commits into from

Conversation

gustavom
Copy link
Owner

Adicionei a opção de remover o registro.

Mas não consegui utilizar a lib DOM para isso, fiz com js puro, pois apareceu um bug, o último registo não era removido, ai fiz assim:
$btnRemove.addEventListener('click', this.removeRegister, false);

mas dessa maneira não funcionou:
$('[data-js="btn-remove"]').on('click', this.removeRegister);

app.js Outdated
},

removeRegister: function removeRegister(e) {
this.parentNode.parentNode.remove();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fala @gustavom! O problema na verdade está na forma de remover o elemento! Provavelmente o this aqui não é quem você esperava que fosse =)

O ideal, para evitar esse tipo de problema, é tentar evitar ao máximo o uso do this. No caso dessa aplicação, você pode precisar dele em alguns momentos, mas tente usar somente onde você sabe que ele não vai mudar, o que não é o caso de callbacks de evento =)

Então, pra resolver, você pode fazer o seguinte: adicione um identificador único em cada linha.. quando clicar em remover, verifique por esse identificador, e então remova a linha. Deu pra sacar? =)

@gustavom
Copy link
Owner Author

Opa @fdaciuk , beleza?

Saquei, essa parada do 'this' parece fácil, mas não é né.

@fdaciuk
Copy link

fdaciuk commented May 21, 2017

É meio chatinho lidar com this no JS por isso mesmo =)
O negócio é evitar ao máximo :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants