How can I stop event propagation with Backbone.js?

前端 未结 5 1091
面向向阳花
面向向阳花 2021-01-31 16:01

Using a Backbone.js View, say I want to include the following events:

    events: {
        \'click a\': \'link\', 
        \'click\': \'openPanel\' 
    }
         


        
5条回答
  •  情歌与酒
    2021-01-31 16:37

    The JQuery preventDefault method would also be a good option.

        window.LocationViewLI = Backbone.View.extend({
            tagName: "li",
            template: _.template('<%= name %>'),
    
            events: {
                "click a": "handleClick"
            },      
            handleClick: function(event) {
                event.preventDefault();
                console.log("LocationViewLI handleClick", this.model.escape("name") );
                // debugger;
            },
            ...
    

提交回复
热议问题