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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:59:34+00:00 2026-06-13T16:59:34+00:00

I am trying to use templating to render a view initially, but to update

  • 0

I am trying to use templating to render a view initially, but to update the view on subsequent calls when it is part of the document.

My app’s page looks a little something like

<body>
  <!-- ... -->
  <div id="view_placeholder"/>
  <!-- ... -->
</body>

And in pseudo-code I want to do something like so

Backbone.View.extend({
  // ...
  render: function() {
    if (this.el *IS NOT A CHILD OF document*) {
      // render the contents from the template
    } else {
      // update the content visibility based on the model
    }
  },
  // ...
});

The reason for this is that the template contains quite a lot of nodes and regenerating it for every change is not practicable.

I have explored some of the data-binding libraries, e.g. rivets.js but they are a poor fit to the template:model relation.

One thing I noticed is that this.el.parentNode==null before I add it to the document, but I am not sure that this is a definitive test, and in any case if I wrap this view within another, then that test becomes less useful (or maybe I am being overly cautious as once within another view’s el I have rendered my sub-template anyway.

Another option I can see is to use a field to track the rendered status, e.g.

Backbone.View.extend({
  //
  templateRendered:false,
  // ...
  render: function() {
    if (!this.templateRendered) {
      // render the contents from the template
      this.templateRendered = true;
    } else {
      // update the content visibility based on the model
    }
  },
  // ...
});

but that feels hacky to me.

So my question is:

What is the best way to track the fact that I have rendered the template fully and therefore only need to tweak the rendered template rather than re-render it (and re-insert all the sub-views)?

  • 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-13T16:59:35+00:00Added an answer on June 13, 2026 at 4:59 pm

    I think the idiomatic backbone approach is to only call a full render() on your view when you want a full render, and use model change event bindings to call sub-render functions that render smaller portions of the view.

    var AddressView = Backbone.View.extend({
        initialize: function (options) {
            Backbone.view.prototype.initialize.call(this, options);
            _.bindAll(this)
            options.model.on('change:name', this.renderName);
            options.model.on('change:street', this.renderStreet);
            options.model.on('change:zipCode', this.renderZipCode);
        },
        renderName: function (model) {
            this.$el.find("#name").text(model.get("name"));
        },
        renderZipCode: function (model) {
            this.$el.find("#zipcode").text(model.get("zipCode"));
        },
        renderStreet: function (model) {
            this.$el.find("#stree").text(model.get("street"));
        },
        render: function () {
            //Populate this.el with initial template, subviews, etc
            //assume this.template is a template function that can render the main HTML
            this.$el.html(this.template(model));
            this.renderName(this.model);
            this.renderZipCode(this.model);
            this.renderStreet(this.model);
            return this;
        }
    });
    

    Code as above is undoubtedly tedious. I would reconsider knockback.js or rivets.js, personally, but I believe the pattern above is the canonical vanilla backbone.js approach.

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

Sidebar

Related Questions

I'm trying to use g.render in a grails service, but it appears that g
Trying to use handlebars.js for templating but the library seems to ignore newlines. What
I have a templating system I was trying to use with my Phonegap App
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use a Java Uploader in a ROR app (for its ease
trying to use hibernate with my web app and getting following exception: Initial SessionFactory
I'm just trying to understand the Templating(system). If you use MVC in your web
So I am trying to use the Cheetah templating engine in conjunction with the
I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
In an attempt to avoid repetition, I am trying to use mustache for templating

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.