开发者

Javascript events multiplying

开发者 https://www.devze.com 2023-03-18 00:54 出处:网络
I can\'t see the forest through the trees. I have a contacts tab with a tableView containing rows that can be deleted. If (in the same session) I delete \'n\' number of rows, the subsequent events are

I can't see the forest through the trees. I have a contacts tab with a tableView containing rows that can be deleted. If (in the same session) I delete 'n' number of rows, the subsequent events are called 'n' times.

Here is my code. (I tried to pare t开发者_JAVA技巧his down to isolate the problem.)

The specific event that is being duplicated (...triplicated, etc) is ui.contactDestroyed because I am getting multiple AlertDialogs as well as multiple resulting app.updateContacts and ui.contactsUpdated fires in my log.

Thanks for any critiques of my code (related to the issue or not).

Note: According to my server log, the otg.remote.destroyContact XHR is appropriately being sent once for each legitimate request. The otg.remote.getContacts XHR is sent multiple times because it is tied to the culprit, ui.contactDestroyed.


line 197 and line 188 should not be in the eventListener, the way the code is written right now, everytime someone deletes something, you are adding a new eventListener, that is why it is happening multiple times.

Add application wide eventListeners once

0

精彩评论

暂无评论...
验证码 换一张
取 消