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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:50:39+00:00 2026-05-28T22:50:39+00:00

I have a very strange behavior in going on KnockoutJS 1.2.1 (Can’t switch to

  • 0

I have a very strange behavior in going on KnockoutJS 1.2.1 (Can’t switch to 2 yet, or believe me I would).

Basically, I have an after render set up on a template. In the after render, I need to retrieve data from my viewModel. When I try to get data from it by viewModel.stuff() inside the render function, a strrrange behavior is occurring. It seems to be calling render multiple times or something.

Here is the code…

var viewModel = {
    stuff: ko.observableArray([{ id : 1, name : 'Thing'},
        { id: 2, name : 'Thingier' },
        { id : 3, name : 'Thingiest' }])

};

window.render = function(el){
    // This line does weird stuff!!
    // Observe the console with and without it
    // All I want to do is get my stuff...
    var stuff = viewModel.stuff(); 
    console.log(el);
};

var update = function(){
    console.log(viewModel);
    viewModel.stuff.push({ id : 4, name : 'Thingiestest' });       
};    

$(function(){
    ko.applyBindings(viewModel);

    $("#add").click(function(){
       update(); 
    });
});

Here is the fiddle…

http://jsfiddle.net/jcreamer898/wZ5bD/

Just try commenting out the var stuff = viewModel.stuff() in the render function and observe the difference in the console log when clicking the button.

Appreciate any help here as I know this one’s a little weird!

  • 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-28T22:50:39+00:00Added an answer on May 28, 2026 at 10:50 pm

    Bindings are executed inside of a computed observable, so when you call viewModel.stuff() in your afterRender function you are creating a dependency for each on the stuff observable.

    When you add a new item, afterRender is getting called after rendering each of the items again.

    Look at the date here: http://jsfiddle.net/rniemeyer/wZ5bD/4/

    I am not sure of the exact thing that you want to accomplish, but if you need to do it in afterRender and don’t want a dependency, then you could perform your action in a setTimeout 0. http://jsfiddle.net/rniemeyer/wZ5bD/5/

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

Sidebar

Related Questions

I noticed very strange behavior of my program today. Basically I have JToolBar uder
I have a very strange behavior with Request.Form . Here are two IIS 7
I have run into a very strange behaviour I can’t make sense of. I
I have a very strange bug, which I believe is caused by some code
I have both VS2008 and VS2010 installed, and I see a very strange behavior
I'm a very strange behavior with EF code first approach and associations. I have
I've written a very simple python numpy code. It have a strange behavior... from
Its very strange behavior that I'm facing. I have delete button, OnClick I'm attaching
I have a very strange behavior when I got mutations in a node in
Today I have faced very strange behavior of sqlite3_finalize statement. I am using sqlite

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.