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

  • Home
  • SEARCH
  • 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 9283535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:39:20+00:00 2026-06-18T18:39:20+00:00

Mates, I’ve got the following code: App.Views.Bed = Backbone.View.extend({ tagName: ‘li’, template: _.template( App.Templates.Bed

  • 0

Mates, I’ve got the following code:

App.Views.Bed = Backbone.View.extend({
tagName: 'li',
template: _.template( App.Templates.Bed ),

events: {
    'click .booked': 'showReservation',
    'click .occupied': 'showGuest',
    'click .free': 'checkIn'
},

render: function(){
    if( this.model.get('id_bookings') ){
        this.clase = 'booked';
    }
    if( this.model.get('id_guests') ){
        this.clase = 'occupied';
    }else{
        this.clase = 'free';
    }
    this.$el.addClass(this.clase).html( this.template( this.model.toJSON() ) );

    return this;
},

checkIn: function(){
    console.log('Check-in form load');
},

showReservation: function(){

},

showGuest: function(){

}

});

I’m trying to trigger a different method depending on the className (which I set depending on the content’s model).

Is there a way to filter by classes when defining a view’s 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-18T18:39:21+00:00Added an answer on June 18, 2026 at 6:39 pm

    In short, it’s not possible using the declarative events hash, unless you’re willing to do some :parent selector hacks, and I’m not sure if that’s even possible, either.

    The problem is that any jQuery selector you use to define the element (for example the class selector .booked) is applied within the view´s el, so the element’s own class is not considered in the selector.

    Instead I would dynamically set the handler method. Something like:

    events: {
        'click': 'onClick'
    },
    
    render: function(){
        if( this.model.get('id_bookings') ){
            this.clase = 'booked';
            this.onClick = this.showReservation;
        }
        if( this.model.get('id_guests') ){
            this.clase = 'occupied';
            this.onClick = this.showGuest;
        }else{
            this.clase = 'free';
            this.onClick = this.checkIn;
        }
        _.bindAll(this, 'onClick');
    
        this.$el.addClass(this.clase).html( this.template( this.model.toJSON() ) );
        return this;
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've currently got an app that me and a few mates have be working
Great Mates... I need your help.. please let me know why this code is
Hello mates i have a page View All Applicants.aspx with gridview and a link
I have got this code: RewriteEngine on RewriteRule (.*)\.php review.php?site=$1 [L] I want to
programmer mates. I was testing java threading capabilities with a very simple code (or
Currently coding a mates portfolio and not to my surprise the code isn't loading
Hi mates i want to print a picture i generated i use the following
I use the following code to access a VSS item: Dim sItem As String
G'Day Mates - What is the right way (excluding the argument of whether it
Well basically, one of my mates was practicing JS and he had an idea

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.