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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:31:08+00:00 2026-06-11T21:31:08+00:00

I am trying to implement select all/none functionality on a list of checkboxes. Clicking

  • 0

I am trying to implement select all/none functionality on a list of checkboxes.

Clicking select all should select the three checkboxes. In the broken example, clicking select all does not update the checkboxes. It does update the array however.

This fiddle works: Working Fiddle

This fiddle does not: Broken Example

The only difference between the two is that ko.mapping is called which does not seem to be setting up the observable array correctly.

var initialData = {"Products":[{"Id":"1","Title":"Item 1"},{"Id":"2","Title":"Item 2"},{"Id":"3","Title":"Item 3"}]};  

var viewModel = ko.mapping.fromJS(initialData); 

What am I doing wrong?

  • 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-11T21:31:09+00:00Added an answer on June 11, 2026 at 9:31 pm

    The problem is that when you use ko.mapping, every property of the input becomes an observable.

    That means in your first sample you can do:

    viewModel.selectAll = function() {
        viewModel.checkedProducts.removeAll();
        ko.utils.arrayForEach(viewModel.Products(), function(product) {
            viewModel.checkedProducts.push(product.Id);  // Id is a plain value
        });
    };
    

    while in your mapping sample you must do:

    viewModel.selectAll = function() {
        viewModel.checkedProducts.removeAll();
        ko.utils.arrayForEach(viewModel.Products(), function(product) {
            viewModel.checkedProducts.push(product.Id());  // Id is an observable!
        });
    };
    

    http://fiddle.jshell.net/ZeCWP/6/


    Really clean would be this:

    viewModel.selectAll = function() {
        viewModel.checkedProducts.removeAll();
        ko.utils.arrayForEach(viewModel.Products(), function(product) {
            viewModel.checkedProducts.push( ko.utils.unwrapObservable(product.Id) );
        });
    };
    

    This would work in both cases. But in a controlled environment it’s not strictly necessary to use unwrapObservable() since you know that the value will always be the an observable or not.

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

Sidebar

Related Questions

I am trying to implement a Select All checkbox using primefaces component p:selectBooleanCheckbox and
I'm trying to implement a Select All menu item for a ListView in a
I am trying to implement something like: Select thread from Thread where(Select Sum(thread.emails) from
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
Trying to implement google C2DM service. registrationIntent.putExtra(app, PendingIntent.getBroadcast(context,0,new Intent(), 0)); registrationIntent.putExtra(sender,example@gmail.com); context.startService(registrationIntent); Almost every
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
Im trying to implement a destructor for the objects of linked-list Iv created. I
I am trying to implement a multi-tenant application, that is - data of all
I am trying to Implement a JFileChooser that allows a user to select files
I am trying to implement a Codeigniter based app on Android via phonegap, all

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.