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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:35:50+00:00 2026-06-01T23:35:50+00:00

I have a KnockoutJS template that looks something like this: <div data-bind=template: {name: ‘testTemplate’,

  • 0

I have a KnockoutJS template that looks something like this:

<div data-bind="template: {name: 'testTemplate', data: people}"></div>

<script id="testTemplate" type="text/html">
    <!--ko foreach: $data-->        
    <div class="items" data-bind="text: full() + ' updated at: ' + Date()"></div>
    <!--/ko-->
</script>

After running Nth number of tests, I realized that creating a template like this is flawed as KnockoutJS will update the template every single time, even if the data doesn’t change.

I’ve illustrated this using these two fiddles:

  • using the foreach binding (works correctly)
  • using the data binding (fails horribly)

As you can see, if you pound the load initial, or load updated data buttons on the foreach binding, the UI is never re-rendered unless the data actually changes. Unfortunately if you do the same on the data style binding, it’s re-rendered every time.

I really can’t figure out what the difference is. I was under the impression that the data binding worked the same way as foreach, but allowed more control of the object inside of the template.

The only reason I’m using it is because I have a set of nested templates, and I needed to get closer to the actual object at hand. I should be able to re-factor, and get away from that approach, but I’m still left wondering why it’s an issue.

Shouldn’t the <!--ko foreach:--> honor the same pattern that the foreach template binding uses?

  • 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-01T23:35:52+00:00Added an answer on June 1, 2026 at 11:35 pm

    The issue is that your template binding creates a subscription to your people observableArray as it is passed as the data. When the people array is updated (items pushed/removed, etc.), then this will trigger the template binding to re-render the template. In your case, this re-renders all of the content, so the foreach inside of the template never gets a chance to be efficient.

    An easy way to avoid this is to make sure that the template binding does not unwrap your people observableArray. You can pass the data like { myArray: people } and then do your foreach on myArray.

    Here is a sample: http://jsfiddle.net/rniemeyer/bVPwM/4/

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

Sidebar

Related Questions

In knockoutjs 1.2.1 I could do: <div data-bind=template: {name: 'Bar', foreach: persons, templateOptions:{fooMode: true}
I have the following table template that is rendered through knockout: <table class=gv data-bind=visible:
I have the following KnockoutJS template (render with jquery.tmpl): <script id=contactsTemplate type=text/html> <li data-bind=click:
Suppose I have knockout.js template like this: <script type=text/html id=mytemplate> <label for=inputId>Label for input</label>
I have a jQuery template, and I would like to use a KnockOutJS template
Let's say I have a template like this <script id=rowTemplate type=text/x-jquery-tmpl> <tr> <a href=${
I have a piece of code working in knockout.js like this: <div> ... some
I've upgraded to KnockoutJs 2 and found that pages that use template bindings have
Currently I have a simple knockoutJS object, with a few observables. But this object
I feel like this must have been asked before, but I've looked at Knockout

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.