Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:58:59+00:00 2026-06-05T01:58:59+00:00

I am working on a nested backbone view, in which if you click on,

  • 0

I am working on a nested backbone view, in which if you click on, it will create a new instance of the same view. I want to disable only a specific event, not all of them; in this case, the click. I tried using undelegateEvents(), but this will disable all the functions. Any ideas on how can this be done?

Here is a piece of the code I am working on:

var View = Backbone.View.extend({
    events: {
        "mousedown": "start",
        "mouseup": "over"
    },

    start: function() {
        var model = this.model;

        var v = new View({
            model: model,
        });
        v.undelegateEvents(); //I just want to disable mousedown
        v.render();
    },

    over: function() {
        /*
        some code here
        */
    },

    render: function() {
        /*
        some code here
        */
    }
});

The idea is to ban clicking in the second instantiated view while keeping the other events. The first one will have all of its events.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:59:00+00:00Added an answer on June 5, 2026 at 1:59 am

    You can specify the events you want to use when you call delegateEvents:

    delegateEvents delegateEvents([events])

    Uses jQuery’s delegate function to provide declarative callbacks for DOM events within a view. If an events hash is not passed directly, uses this.events as the source.

    So you could do something like this:

    var v = new View({
        model: model,
    });
    v.undelegateEvents();
    var e = _.clone(v.events);
    delete e.mousedown;
    v.delegateEvents(e);
    v.render();
    

    You might want to push that logic into a method on View though:

    detach_mousedown: function() {
        this.undelegateEvents();
        this.events = _.clone(this.events);
        delete this.events.mousedown;
        this.delegateEvents();
    }
    
    //...
    
    v.detach_mousedown();
    

    You need the this.events = _.clone(this.events) trickery to avoid accidentally altering the “class’s” events (i.e. this.constructor.prototype.events) when you only want to change it for just one object. You could also have a flag for the View constructor that would do similar things inside its initialize:

    initialize: function() {
        if(this.options.no_mousedown)
            this.detach_mousedown()
        //...
    }
    

    Another option would be to have a base view without the mousedown handler and then extend that to a view that does have the mousedown handler:

    var B = Backbone.View.extend({
        events: {
            "mouseup": "over"
        },
        //...
    });
    var V = B.extend({
        events: {
            "mousedown": "start",
            "mouseup": "over"
        },
        start: function() { /* ... */ }
        //...
    });
    

    You’d have to duplicate the B.events inside V or mess around with a manual extend on the events as _.extend won’t merge the properties, it just replaces things wholesale.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a navigation control. I have nested lists which creates this: What
I'm trying to get a nested loop working that will display 6 posts with
I'm working the linkbutton in a nested masterpage and want to pass a value
I'm working on a documentation (personal) for nested matplotlib (MPL) library, which differs from
I'm trying to get nested master pages working with the new razor syntax. Any
I am working with a two nested data repeaters, and I want to allow
hello I have question on nested select in mysql. I want a working query
I'm working with a tree structure in MySQL that is respresented using the nested
Good day. Has somebody working solution for deleting asset in nested form in Carrierwave?
I'm trying to get my backbone associations working inside a rails app , and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.