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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:38:20+00:00 2026-06-14T15:38:20+00:00

I am trying to understand some slightly odd behavior I am seeing in a

  • 0

I am trying to understand some slightly odd behavior I am seeing in a page I am making using KnockoutJS. An observable array seems to get duplicate items every time I clear and reapply bindings. The quickest way to understand the problem is to look at this JSFiddle demo. Just click any edit button several times, and watch this list grow!

The heart of the code for this demo is in the following method:

var _bindItemDetail = function (jsonData) {
        //clear existing bindings
        ko.cleanNode($("#itemdetails").get(0));

        // observables in selected item.
        _viewModel.SelectedItem(ko.mapping.fromJS(jsonData));

        // Apply Bindings
        ko.applyBindings(_viewModel.SelectedItem, $("#itemdetails").get(0));
    };

The essence of what I am trying to achieve is to create a list and details page in one. The list JSON is fetch on initial page load, and the detail JSON is fetched and bound to the “detail” html whenever an edit link is clicked.

In addition to solving the problem, I am trying to understand the behavior, and learn some lessons about how to clean up stale resources properly when using knockout.

Thanks for any help

  • 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-14T15:38:21+00:00Added an answer on June 14, 2026 at 3:38 pm

    The problem is that in your _bindItemDetail function, you are reapplying the bindings on your modified view where you already had replicated the elements.

    var _bindItemDetail = function (jsonData) {
        //clear existing bindings
        ko.cleanNode($("#itemdetails").get(0));
    
        // observables in selected item.
        _viewModel.SelectedItem(ko.mapping.fromJS(jsonData));
    
        // Apply Bindings
        ko.applyBindings(_viewModel.SelectedItem, $("#itemdetails").get(0));
    };
    

    ko.cleanNode() merely removes bindings from the elements, it doesn’t revert the view back to its initial state. In general, you should only ever call ko.applyBindings on a set of nodes once. Doing it more than once, is just asking for problems.

    Frankly you’re not really making good use of knockout. The majority of your code is using jquery to handle all the low-level details. The point of using knockout is to not have to worry about those lower level details.

    I’ve adjusted your fiddle a bit to make better use of knockout with less emphasis on using jquery.

    In the view:

    • Used the click binding to handle your Edit click events.
    • Used the with binding to conditionally show the editor fields. The stopBindings handler is not needed.

    In the view model:

    • Added the click handler editClicked to the view model.
    • Removed jquery event bindings.
    • Removed the ko.cleanNode/ko.applyBindings combo you had when binding items. You shouldn’t do that and you just don’t need it, knockout will handle all that for you.

    Updated fiddle

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

Sidebar

Related Questions

I'm trying to understand some behavior I'm seeing in the context of sending UDP
I am trying to understand some example code on this web page: ( http://www.csharp-station.com/HowTo/HttpWebFetch.aspx
I'm trying to understand some code in the D language runtime. It seems like
I'm trying to understand some of the function in WordPress, but I can't get
I'm trying to understand some quirks of the Parallelize[] behavior. If I do: CloseKernels[];
I'm trying to understand some of the basics of using POSIX pthreads. The kind
I am now trying to understand some code and I have found a pattern,
I'm trying to understand some MATLAB source codes. I don't know exactly which one
This might be difficult to answer. I am trying to understand some codebase and
I have some legacy C++ code that I am trying to understand a bit

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.