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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:05:48+00:00 2026-06-08T02:05:48+00:00

I have an array that I’m removing items from but I’m keeping count of

  • 0

I have an array that I’m removing items from but I’m keeping count of the number of items to do UI formatting. I need to be able to have the bind update.

    ko.applyBindings(viewModel);
    getFoos();


var viewModel = {
    foos: ko.observableArray([]),

    reloadFoos: function () {
        getFoos();
    },

    removeFoo: function () {
        remove(this);
    }
};

var foo = function () {
    this.Id = ko.observable();
    this.Name = ko.observable();
    this.Count = ko.observable();
};

function remove(foo) {
    viewModel.foos.splice(viewModel.foos.indexOf(foo), 1);

    viewModel.foos.each(function(index) {
        viewModel.foos[index].Count = index%10 == 0;
    });
}

function getFoos() {
    viewModel.foos([]);
    $.get("/myroute/", "", function (data) {

        for (var i = 0; i < data.length; i++) {
            var f = new foo();
            f.Id = data[i];
            f.Name = data[i];
            f.Count = i%10 == 0;
            viewModel.foos.push(f);
        }

    });
}

            <div data-bind="foreach: foos">
                <div style="float: left">
                        <a href="javascript:void(0);" data-bind="click : $parent.removeFoo, attr: { id: Id }">
                            <label data-bind="value: Name"></label>
                        </a>
                </div>
                <!-- ko if: Count -->
                <div style="clear: left"></div>
                <!-- /ko -->
            </div>

When the click event fires the item is removed from the array but the if bind doesn’t get updated and the ui formatting is off. I’m trying to keep from reloading the data because the ui block bounces as it removes and reloads.

  • 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-08T02:05:50+00:00Added an answer on June 8, 2026 at 2:05 am

    Your UI is not being updated because when you do your assignment to Count, you aren’t assigning as an observable. You are replacing the observable with a straight boolean value. So, your assignment calls like this one:

    viewModel.foos[index].Count = index%10 == 0;
    

    Will cause viewModel.foos[index].Count to be equal to true or false and the value won’t be stored in the observable.

    That line should be this instead:

    viewModel.foos[index].Count(index%10 == 0);
    

    That will set the observable correctly. Note that you must change all of your assignments to observables to be set this way. See the “Reading and Writing Observables” section of this page: Knockout Observables.

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

Sidebar

Related Questions

I have an array that is produced from people wanting to reserve a time
I have an array that is already sorted but i want to give a
I have an array that is built using the explode() function, but seeing how
I have an array that I need to rearange a bit. I am building
I have an array that has sequential array keys and I need to randomly
I have an array that gets created from JSON. The array looks like this:
I have a two dimensional array that I need to load data into. I
I have an array that can contain any number of elements. Each element contains
i have an array that named detailTexts that having his data from floats: CLLocation
I have array that need to sort by their appearance, as they are written

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.