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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:25:32+00:00 2026-05-23T10:25:32+00:00

So for example the observable array is set-up using the mapping function (ko.mapping.fromJS). How

  • 0

So for example the observable array is set-up using the mapping function (ko.mapping.fromJS).
How do I data-bind the visibility of a div based on a value inside the observable array?

  • 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-05-23T10:25:32+00:00Added an answer on May 23, 2026 at 10:25 am

    It is important to note that when you use ko.observableArray, it is only observing the array and not the individual objects in the array. So if anything is pushed or popped from the array, then knockout will notice that and update the templates but if there is a change in an individual object of an array e.g. a certain property of an array member is changed, knockout will not update the templates.

    The solution is to observe array members inside the array separately which you want to subscribe to. In your case lets say if the value inside the observable array reside in the first index member then you would need to do the following in your view model:

    theArray: ko.observableArray(initialArray);
    theValue: ko.observable(this.theArray[0]);
    

    and div visibility :

    <div data-bind="visible: theValue.something"></div>
    

    EDIT:

    The problem with your scenario is that the if a certain users becomes an Admin, knockout will NOT render the template because it is not tracking individual properties of each user in the array. It will ONLY render the template when you add/delete the users array.

    To ensure that it re-renders the template if a user is set as Admin, we need to do something like this >

    //declare the view model
    var viewModel = {
       users: ko.observableArray(listOfUsers); //you need to pass the users list array you get from ko.mapping
    }
    
    //make each array member observable
    for (var i = 0; i < viewModel.users().length; i++) {
       viewModel.users()[i] = ko.observable(users()[i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

example: I want to see if array[5] holds a value or is empty.
Please consider the following view: <p>Count <span data-bind=text: unreadCount()>&nbsp;</span></p> <div data-bind='template: { name: conversationTemplate,
I bind observable collection on listBox. I have data tempate on listbox item. It
Example int *ptr; *ptr = 1000; can I catch memory access violation exception using
Do properties on an object within an Observable collection require a PropertyChangedEvent? For example:
Let's say for example that I have two functions with random code inside and
I'm trying to add a new item to an observable array when a button
I'm using an observable collection to hold all files dragged into a ListBox control
I'm trying to understand the Observer and the Observable. Here's an example that I'm
I need to bind a textblock.text property to a single element in an observable

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.