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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:33:55+00:00 2026-05-25T19:33:55+00:00

I was working with a simply template, containing an {{each}} block. The whole template

  • 0

I was working with a simply template, containing an {{each}} block. The whole template would get re-rendered every time something changed in the collection.

I then attached an afterRender event in the template binding. The function called would simply set the focus to the newly added input element. Working perfectly.

{{each Fabbricati}}
<li>
    <div style="float: left; clear: left;">
        {{if Editing}}
        <input id="editingitem" type="text" data-bind="value: Name, event: { blur: function() { Editing(false) }, keypress: function(event) { if (event.which == 13) { blur() } return true; } }" />
        {{else}}
        <span data-bind="click: function() { Editing(true) }">${Name() || 'Senza nome'}</span>
        {{/if}}
        - <button class="fancybox edit" data-bind="click: function() { Edit(Id()) }">Modifica</button><button class="remove" data-bind="click: Remove">Rimuovi</button>
    </div>
</li>
{{/each}}

and the calling div:

<div id="wrapper" data-bind="template: { name: 'navTemplate', afterRender: Prettify </div>

Now I tried to move the block inside the {{each}} to a standalone template, and call it using the “foreach” option in the template binding. So far so good, but here’s the catch: afterRender won’t work anymore. My input won’t get the focus.

I already read around the internet that it is intended behaviour, and to use afterAdd instead, but this isn’t working too. The effects of my Prettify function are always added to all elements except the last one added. If I add another one, the previous gets the behaviour, etc.

I’m really stuck. If anyone knows how to fix this, it would be a life saver.

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-05-25T19:33:56+00:00Added an answer on May 25, 2026 at 7:33 pm

    I would try taking a look at the new version of knockout in beta at https://github.com/SteveSanderson/knockout/tree/1.3. It has some different ways of doing the bindings that are simpler and may meet your needs better. There is a writeup of new features at http://blog.stevensanderson.com/2011/08/31/knockout-1-3-0-beta-available/.

    I had some issues similar to what your’re having, but used the new control flow bindings as was able to simplify my code a lot. See below.

    With regards to afterRender:

    <ul data-bind="foreach: products, afterRender: callback">
    <li>
        <strong data-bind="text: name"></strong>
        &mdash;
        Last updated: <em data-bind="text: $parent.lastUpdated"></em>
    </li>
    

    This is similar to code I was running yesterday. I found that afterRender was called every time a row was generated. I think this is behavior you’re looking for. Knockout 1.3 Beta Note – afterRender & IE9 have an issue as of today as it will cause an exception.

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

Sidebar

Related Questions

I'm working on a simply password strength checker and i can not success applying
I'm working with various XML inputs and outputs and simply want to grab the
I am using opencv for real-time template matching. The camera yields at 52fps grayscale
I'm struggling to get web.config transformations working with automated builds. We have a reasonably
Forum; I am a newbie working out a bit of code. I would like
I have a large unordered list, each containing a picture and a title. When
I'm currently working on a system that is using handlebars.js template's. It's working for
I am working on a RoR website and would like to handle server errors
I am working on a simple textBox template, which is just two borders, one
I am working on writing a Django app for the first time, so bear

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.