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 7804457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:55:16+00:00 2026-06-02T01:55:16+00:00

This code does not have much context, but will illustrate my question. It’s a

  • 0

This code does not have much context, but will illustrate my question. It’s a Backbone view defined in an AMD module which I use to load via require.js

Essentially I want to be able to add events to a Backbone view after initialization has been run. At the moment I am making an empty events object, and then in a method called addView, I add an event each time the function is called. This is not currently working.

I’m not sure at what point the events are registered, but I’m suspecting that I somehow have to get the view to update it’s listeners when the events object changes?

Does anybody know how I can achieve adding events to a Backbone.js after initialization?

   define([
    'jQuery',
    'Backbone'],

    function ($, Backbone) {

        var contentViews = new Array();

        var SlidePanelView = Backbone.View.extend({

            events: {},

            /// <param name="targetDataAtt">The unique value inside the target's Data-Slide-Panel-Id attribute</param>  
            /// <param name="event">Backbone event to trigger view</param>
            /// <param name="destroyOnRemove">True to destroy view when removed, False otherwise (Default true)</param>  
            addView: function (targetDataAtt, event, view, destroyOnRemove) {
                destroyOnRemove = typeof destroyOnRemove !== 'undefined' ? destroyOnRemove : true;

                this.events[event] = "viewEventFired";
                contentViews[targetDataAtt] = { View: view, DestroyOnRemove: destroyOnRemove };
            },

            viewEventFired: function (e) {

                var target = $(e.target);
                var id = target.attr('data-slide-panel-id');
                console.log(id);
            }

        });

        // Return a singleton??
        return new SlidePanelView;


    });
  • 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-02T01:55:18+00:00Added an answer on June 2, 2026 at 1:55 am

    If I’m understanding the question correctly, after you add additional events to the events hash, call delegateEvents() on the view to re-bind events.

        addView: function (targetDataAtt, event, view, destroyOnRemove) {
           destroyOnRemove = typeof destroyOnRemove !== 'undefined' ? destroyOnRemove : true;
           this.events[event] = "viewEventFired";
           this.delegateEvents();
           contentViews[targetDataAtt] = { View: view, DestroyOnRemove: destroyOnRemove };
        }
    

    It does unbind all the existing event bindings and rebinds all the events in the events hash again, and I’m not sure of the underlying performance issues of doing that, but its something to be aware of.

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

Sidebar

Related Questions

I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this email sending code that does not show a chooser (good). How
This code does not throw an error but the query fails, that is, the
This javascript code does not work in IE8, but works in Firefox and Google
It appears this code will request the file in Chrome and IE but not
This is a very general question, and I think my context does not matter
This code does not function as expected: // $field contains the name of a
Why this code does not compile (Cygwin)? #include <vector> template <class Ttile> class Tilemap
Could someone tell me why this code does not update the data response? It's
For some reason, this code does not actually draw my bitmap file... or show

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.