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

The Archive Base Latest Questions

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

I’m doing an app that basically works like the facebook wall. Essentially Posts and

  • 0

I’m doing an app that basically works like the facebook wall.

Essentially Posts and Comments.

It’s working, but in order to render the CommentView, I’m using code similar to this in my Post Template

<div class="wall-post"> 
    <div class="wall-post-content">${PostContent}</div>        
    <div class="wall-post-comments" id="wall-post-comments-${PostId}"></div>
</div>

Then I use the id of the comment area for that post like this.

var comment_view = new PostCommentView({ model: post.get("Comments") });
this.$('#wall-post-comments-'+ post.get("PostId")).append($(comment_view.render()));

This works, but something tells me I shouldn’t be manually binding against my own ID. I feel I should be doing something clever with this.el ?

Can anyone point me in the right direction.

I’m using BackBone Relational to manage the relationships.

//EDIT

As requested some more of the implementation

//Some functions relating to click evens and functionality removed, as I don’t think they relate to my question.

PostModel = Backbone.RelationalModel.extend({
urlRoot: '/api/post',
idAttribute: 'PostId',
relations: [{
    type: Backbone.HasMany,
    key: 'Comments',
    relatedModel: 'CommentModel',
    reverseRelation: {
        key: 'Post',
        includeInJSON: 'PostId'
    }
}]
});


CommentModel = Backbone.RelationalModel.extend({
    urlRoot: '/api/comment',
    idAttribute: 'PostId'
});


PostCollection = Backbone.Collection.extend({
    url: '/api/post',
    model: PostModel
});


PostListView = Backbone.View.extend({
tagName: 'div',

className: 'PostListView',

initialize: function(){
    _.bindAll(this, 'render', 'render_thread_summary', 'on_submit', 'on_thread_created', 'on_error');
    this.model.bind('reset', this.render); 
    this.model.bind('change', this.render); 
    this.model.bind('add', this.render_thread_summary); 
},
 template: $('#wall-post-template').html(),

render: function() {
    $(this.el).html($(this.template).tmpl(this.model.toJSON()));

    this.model.forEach(this.render_thread_summary);
    return $(this.el).html();
},
render_thread_summary: function(post) {
        var comment_view = new PostCommentView({ model: post.get("Comments") });
        this.$('#wall-post-comments-'+ post.get("PostId")).append($(comment_view.render()));
}
});


PostCommentView = Backbone.View.extend({   

initialize: function(){
    _.bindAll(this, 'render', 'on_click');
    this.model.bind('change', this.render);
},

template: $('#wall-comments-template').html(),
render: function() {
    var html = $(this.el).html($(this.template).tmpl(this.model.toJSON()));
    return html;
}
});
  • 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-02T17:08:56+00:00Added an answer on June 2, 2026 at 5:08 pm

    I was greatly underusing the this.el reference. There is no need to generally use id’s for most things on the page, as within a view you can just reference $(this.el) and then reference from that part of the page. $(“.className”, this.el) will select any class’s with in the item on the page. el is essentially a reference to the area on the page where the view was rendered to. It’s really clean once you get the hang of it.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
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
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.