首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将多个函数绑定到视图的单击事件

将多个函数绑定到视图的单击事件
EN

Stack Overflow用户
提问于 2014-02-18 18:00:16
回答 1查看 1.5K关注 0票数 3

我试图将几个函数绑定到单击事件。我要说的是:

代码语言:javascript
复制
var Foreground = Backbone.Marionette.Layout.extend({

    el: $('body'),

    events: {
        'click': 'tryResetContextMenu onClickDeselectCollections'
    },

    //  Whenever the user clicks on any part of the UI that isn't a multi-select item, deselect the multi-select items.
    onClickDeselectCollections: function (event) {
        console.log("deselect collections");
        var isMultiSelectItem = $(event.target).hasClass('multiSelectItem');
        var isChildMultiSelectItem = $(event.target).closest('.multiSelectItem').length > 0;

        if (!isMultiSelectItem && !isChildMultiSelectItem) {
            this.deselectCollections();
        }
    },

    //  If a click occurs and the default isn't prevented, reset the context menu groups to hide it.
    //  Child elements will call event.preventDefault() to indicate that they have handled the context menu.
    tryResetContextMenu: function (event) {
        console.log("resetting context menu items");
        if (event.isDefaultPrevented()) {

            //  TODO: I don't think this is the proper way to do this. I should be showing a new view with top/left defined?
            this.contextMenu.currentView.show({
                top: event.pageY,
                //  Show the element just slightly offset as to not break onHover effects.
                left: event.pageX + 1
            });

        } else {

            //  Clearing the groups of the context menu will cause it to become hidden.
            ContextMenuItems.reset();
        }
    }
});

这两种功能都不启动,但单独工作很好。支持此功能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-18 18:04:57

就像这样:

代码语言:javascript
复制
events: {
    'click': function(event) {
                 this.tryResetContextMenu(event);
                 this.onClickDeselectCollections(event);
             }
},
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21861789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档