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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:16:25+00:00 2026-06-01T03:16:25+00:00

This problem is going to be hard for me to explain but I will

  • 0

This problem is going to be hard for me to explain but I will try my best.

When a user clicks a UserView it uses the same model to show a more detailed ProfileView

If the user clicks on more than one UserView and then decides to click on the chat button that is on each ProfileView. Every model that the user has clicked on in the is outputted

So say I have clicked 3 profiles and then I click on the chat button it will output this to the console.

"start chat with >" model1
"start chat with >" model2
"start chat with >" model3

I only want the user that was last clicked on…

Can anyone explain to my why these models are stacking up?

Here is the code that you might need.
UserView which represents each model in my collection.

var UserView = Backbone.View.extend({
    tagName: 'li',
    className: 'user',
    template: $('#tUser').html(),
    events: {
        'click' : 'clicked'
    },

    initialize: function() {
        this.render();
    },

    render: function() {
        var user = _.template(this.template, this.model.toJSON());
        //this.el.html(user);
        var show = this.$el.html(user); 
        $('#users').append(show);
        return this;
    },

    clicked: function() {
        new ProfileView({model: this.model});
    }
});

As you can see I have set up a click event when a UserView is clicked and then it instantiates a ProfileView using the current model.

var ProfileView = Backbone.View.extend({
    el: '#profiles',
    template: $('#tProfile').html(),

    events: {
        'click .chat' : 'startChat'
    },

    initialize: function() {
        _.bindAll(this, 'render');
        console.log('profile', this.model.toJSON());
        this.render();
    },

    render: function() {
        var user = this.model.toJSON();
        var profile = _.template(this.template, this.model.toJSON());
        var show = this.$el.html(profile);
        return this;
    },

    startChat: function() {
        console.log("start chat with", this.model.toJSON());
    }
});
  • 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-01T03:16:26+00:00Added an answer on June 1, 2026 at 3:16 am

    Unless you plan on having more than one profile view visible on the screen at any given time, you should convert your profileView into a singleton.

    Your UserView first checks if it has an assigned profile, and simply updates the model if so:

    var UserView = Backbone.View.extend({
        tagName: 'li',
        className: 'user',
        template: $('#tUser').html(),
        events: {
            'click' : 'clicked'
        },
    
        initialize: function() {
            this.render();
        },
    
        render: function() {
            var user = _.template(this.template, this.model.toJSON());
            //this.el.html(user);
            var show = this.$el.html(user); 
            $('#users').append(show);
            return this;
        },
    
        clicked: function() {
            if (this.profileView){
                this.profileView.unrender();
                this.profileView.model = this.model;
            } else {
                this.profileView = new ProfileView({model: this.model});
            }
            this.profileView.render();
        }
    });
    

    ProfileView no longer renders on instantiation:

    var ProfileView = Backbone.View.extend({
        el: '#profiles',
        template: $('#tProfile').html(),
    
        events: {
            'click .chat' : 'startChat'
        },
    
        initialize: function() {
            _.bindAll(this, 'render');
            console.log('profile', this.model.toJSON());
        },
    
        render: function() {
            var user = this.model.toJSON();
            var profile = _.template(this.template, this.model.toJSON());
            var show = this.$el.html(profile);
            return this;
        },
    
        startChat: function() {
            console.log("start chat with", this.model.toJSON());
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this is going to be hard to explain but here goes nothing: Lately
This is going to be fairly hard to explain, so I've put together a
It is hard to put this problem into words, but a real world example
Ok this is a little hard to explain but here I go. On View1
I'm going to try and explain this as simply as I can, it's most
I've been going at this problem for a solid couple hours now and having
I think this is going to be one of those simple-when-you-see-it problems, but it
This problem occurs when I try to hide a file in my directory with
I was thinking about a typical problem that is very JIT-able, but hard to
this one is hard to explain! I am writing a python application to be

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.