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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:25:56+00:00 2026-06-13T11:25:56+00:00

I’m new to Backbone and would like some light shed on how I should

  • 0

I’m new to Backbone and would like some light shed on how I should approach this. I might be not using the right definitions here – sorry in advance!

Currently I have rows of elements that each have a button (I’ll refer to these buttons as button A). These rows are generated as Rails partial. The button opens a popup box that has some controls specific to that row of information. Code-wise, there is only one popup box that adjusts itself + information inside it each time any of the button A is clicked, and it is located in an index.html.erb file.

I want to turn these code into Backbone view object – but I don’t know how to make the pop up box view interact with multiple buttons.

Would a right way to approach this be create a pop-up box per button and let there be multiple pop-up views that communicate with each other? What would be the right approach for this?

Currently, none of these elements are backbone view object.

Thank you in advance.

  • 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-13T11:25:57+00:00Added an answer on June 13, 2026 at 11:25 am

    I’m assuming:

    • You’re referring to a modal popup box, not a popup window. If you were trying to change the content of a popup window, you’d simply load a new URL that displays the data you’re expecting.
    • All the HTML markup has already been created by your Rails templates
    • You’re using jQuery

    JSFiddle example: http://jsfiddle.net/4J6fL/

    The first step is to create a Backbone.View instance that is responsible for the functionality of your data list.

    var DataView = Backbone.View.extend({
        events: {
            // this event will be bound to every button inside our parent element
            "click button": "enlarge"
        },
    
        enlarge: function(e) {
            // backbone rebinds 'this' to refer to the View. It will not refer to the element 
            // triggering the event as it would in jQuery. Grab a reference to the triggering element.
            $el = $(e.currentTarget);
    
            // gather the data for our popup window
            var popupData = {
                title: $el.siblings('p').text(),
                img: $el.siblings('img').attr('src')
            };
    
            this.popup(popupData);
        },
    
        popup: function(data) {
            // find the view's popup box element - this.$el refers to the views bound DOM element
            var $enlarged = this.$el.find('#enlarged');
    
            // create new elements based on the data
            var $title = $('<h2 />', { text: data.title });
            var $img = $('<img />', { src: data.img });
    
            // empty the popup box of current data
            $enlarged.html('');
    
            // fill the popup box with our new data
            $enlarged.append($title);
            $enlarged.append($img);
        }
    });
    

    At this point we have a View which can be bound to any DOM element, giving it the above functionality.

    • The events property is responsible for binding event callbacks to the view.
    • Be aware of the context of this in your callbacks, Backbone binds it to the View, not the event.
    • this.$el refers to the DOM element bound to our view. You’ll see how to do further on.
    • The actual popup logic is standard jQuery DOM manipulation.

    Now that we have our view, we need to initialize and use it. This is done in the Backbone.Router, which acts as a controller:

    dataView = new DataView({ el: $('#data-view') });
    

    Notice how we’re passing the element (el) that will be bound to this view? This is what binds a DOM element to our view, allowing us to manipulate it from within the view.

    The next logical step would be to separate the popup code into another view, using events to signal when it should be updated. This would allow you to easily trigger the popup from other areas of your page.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.