Catch all events except in reset

若如初见. 提交于 2019-12-12 16:05:49

问题


I wanna catch all events except 'reset'. I've a code like this initialized inside a View.

messagesCollection.on 'all', @_handleMessageChanges, @

Right now it works for all events. As I've mentioned above I don't need to catch in a reset event.

How can I resolve this issue? Please help us.


回答1:


When using all, the first argument is the event. So, you can do

_handleMessageChanges: function(event, ...) {
    if ( event === 'reset' ) return;
} 

See it in action here: http://jsfiddle.net/nxs9q/1

From the docs:

"all" — this special event fires for any triggered event, passing the event name as the first argument.



来源:https://stackoverflow.com/questions/18457694/catch-all-events-except-in-reset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!