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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:27:10+00:00 2026-06-03T02:27:10+00:00

It seems Knockout’s convenient afterRender method on foreach bindings only fires when data is

  • 0

It seems Knockout’s convenient “afterRender” method on foreach bindings only fires when data is added, and not removed.

You can test that here – http://jsfiddle.net/farina/4BaXs/1/ by clicking load initial, seeing the four alerts, then clicking load delete and notice nothing happens.

So, to solve this problem I decided to attempt to create a manual subscription to my ko.mapping.fromJS array, but that just results in a call every time I update the data from AJAX, even if the data hasn’t changed.

I feel like the mapping plugin is somehow failing, and thinking that the data is always new, even when it is not.

Is there some sort of event which only occurs when the array has changed? My subscriptions on individual items work as expected, but obviously you can’t subscribe to an entire list of items?

  • 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-03T02:27:11+00:00Added an answer on June 3, 2026 at 2:27 am

    I wrote up a function that uses ko.utils.compareArrays to figure out what has changed. compareArrays is also used by the foreach binding. I also took your example and updated it to use this function. Here it is:

    ko.subscribable.fn.subscribeArrayChanged = function(addCallback, deleteCallback) {
        var previousValue = undefined;
        this.subscribe(function(_previousValue) {
            previousValue = _previousValue;
        }, undefined, 'beforeChange');
        this.subscribe(function(latestValue) {
            var editScript = ko.utils.compareArrays(previousValue, latestValue);
            for (var i = 0, j = editScript.length; i < j; i++) {
                switch (editScript[i].status) {
                    case "retained":
                        break;
                    case "deleted":
                        if (deleteCallback)
                            deleteCallback(editScript[i].value);
                        break;
                    case "added":
                        if (addCallback)
                            addCallback(editScript[i].value);
                        break;
                }
            }
            previousValue = undefined;
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that knockout is not mapping the properties of objects in an array
Most of Knockout seems very intuitive. One thing that is strange to me though
With Knockout 2.0 using this data-bind: data-bind=click: $root.deleteSomeEntity.bind($data, $parent) in the Knockout viewmodel JavaScript
Is there any option to suspend and resume bindings in knockout? Version : knockout.js
Seems that there are not much work done on Haskell for web. People uses
Seems to me it is a bit wierd that you can do.. Page.ClientScript.RegisterStartupScript(this.GetType(), KeyName,
Seems archive file can be generated from object file: ar rvs libprofile.a profile.o What's
I've just started playing around with Knockout.js, and it seems really cool. What I
Seems begineer but i really do not understand what these lines of code saying,
Seems like a simple enough question but I can't seem to find the answer.

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.