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

  • Home
  • SEARCH
  • 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 8728045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:33:02+00:00 2026-06-13T08:33:02+00:00

In my ViewModel I have: self.collaps = ko.observableArray([0,0,0,0,0,0,0]); self.shouldShow = function(index) { return self.collaps()[index];

  • 0

In my ViewModel I have:

self.collaps = ko.observableArray([0,0,0,0,0,0,0]);

self.shouldShow = function(index) { return self.collaps()[index]; };

My test div:

<div data-bind="visible: shouldShow(5)">Shown!</div>

I data-bind a button with click: show :

self.show = function() {
    // 1. Index 5 gets true after 2 clicks!!? But UI never updates!
    self.collaps()[5] = true;

    // 2. This is push-ing in true starting at index 0
    self.collaps.replace(self.collaps()[5], true);

    // 3. If I combine the two, I get the behavior I want, I think :)
    self.collaps()[5] = true;
    self.collaps.replace(self.collaps()[5], true);

};

What is happening here? What is the right way of doing this?

—-> JSFIDDLE for your pleasure! <—-

  • 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-13T08:33:03+00:00Added an answer on June 13, 2026 at 8:33 am

    Here is a quote from the ko documentation:

    Key point: An observableArray tracks which objects are in the array,
    not the state of those objects

    Simply putting an object into an observableArray doesn’t make all of
    that object’s properties themselves observable. Of course, you can
    make those properties observable if you wish, but that’s an
    independent choice. An observableArray just tracks which objects it
    holds, and notifies listeners when objects are added or removed.

    So when you are changing array item’s value knockout is not notified. You can use valueHasMutated function to notify subscribers manually:

    self.show1 = function() {
        self.test(self.test()+1);
    
        self.collaps()[5] = true;
        self.collaps.valueHasMutated();
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a knockoutjs viewmodel defined like this: function TestViewModel() { var self =
I have the following knockout viewmodel: function DepartmentsViewModel() { var self = this; self.currentComplaint
I have a template binding to an observableArray <ul data-bind=template: { name: 'defaultTemplate', foreach:
I have the following code: function ViewModel() { var self = this; self.deckareax =
I have this little ViewModel: function BooksViewModel() { var self = this; self.books =
I have a method on my viewModel like so: self.search = function () {
I have one of my ViewModels as: Models.DayP = function (data) { var self
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have a search form: <form class=navbar-search pull-right data-bind=submit: findBook> <input type=text class=search-query placeholder=Search
I have a Knockout view model defined like this: function viewModel () { var

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.