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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:31:45+00:00 2026-06-08T14:31:45+00:00

[My first attempt at describing the issue was clear as mud; I significantly reworked

  • 0

[My first attempt at describing the issue was clear as mud; I significantly reworked it in the name of clarity. I hope I haven’t failed miserably…again.]

I’m attempting to set up a master/details view using knockout where the details pane includes a list of checkboxes. I have an array of User objects, each of which has in turn an array of UserPermission objects where the PermissionId property is what should determine if the checkbox is checked.

So, in short: There’s a master list of users, from which you select one to view details. In the details pane, I have a list of checkboxes (generated from a list of available permissions). Whether or not a given checkbox is checked should be determined by the persences of a matching PermissionId within the array of UserPermission objects associated with the current user.

My question is – how do I get the checkboxes to use the user.UserPermissions.PermissionId for the checked binding?

Here’s a jsfiddle of my attempt thus far, and here’s another approach I’ve tried.

  • 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-08T14:31:46+00:00Added an answer on June 8, 2026 at 2:31 pm

    After a bit of tinkering, I’ve got a solution for you, though it’s not a trivial change.

    I made a few attempts at tweaking what you had, but it became obvious that I needed to approach the problem differently.

    So, I started by separating the population of the view model from the definition of the view model.

    Here’s the view model definition:

    var AppViewModel = function() {
        var self = this;
    
        //list of client users
        self.users = ko.observableArray();
    
        //list of permissions available to this client
        self.permissions = ko.observableArray();
    
        //user to display in details area
        self.currentUser = ko.observable();
    
        //select user from the master list
        self.selectUser = function(u) {
            self.currentUser(u);
        };
    }
    

    This is the same as what you had, except that the function does not expect data to be passed in.

    The binding of this view model now looks like this:

    var viewModel = new AppViewModel();
    ko.applyBindings(viewModel);
    addPermissions(initialData.PermissionList);
    addUserAccounts(initialData.UserList);
    

    Of course, the details of the addPermissions and addUserAccounts functions are in my resulting fiddle, and I’ll provide the link to that in a bit.

    Let me first discuss the solution for binding whether or not a checkbox is checked.

    I took a look at the documentation on using checked, and I noticed that in one of the examples, the bound value is an array.

    So, to take advantage of that, I created a UserAccount class:

    var UserAccount = function() {
        var self = this;
    
        self.id = ko.observable();
        self.email = ko.observable();
        self.clientId = ko.observable();
        self.firstName = ko.observable();
        self.lastName = ko.observable();
        self.createdBy = ko.observable();
        self.userPermissions = ko.observableArray();
    };
    

    When a UserAccount is added to the view model, it uses the following function:

    var addUserAccount = function(data) {
        var userAccount = new UserAccount();
        userAccount.id(data.UserId);
        userAccount.email(data.UserEmail);
        userAccount.clientId(data.ClientId);
        userAccount.firstName(data.FirstName);
        userAccount.lastName(data.LastName);
        userAccount.createdBy(data.CreatedBy);
    
        for(var i = 0; i < data.UserPermissions.length; i++) {
            var permissionIdAsString = String(data.UserPermissions[i].PermissionId);
            userAccount.userPermissions.push(permissionIdAsString);
        }
        viewModel.users.push(userAccount);
    };
    

    Notice the for loop in this function, which is simply adding each of the PermissionId values from the UserPermissions array to the userPermissions observableArray of the UserAccount.

    Note also that the available permissions are now each represented by an instance of the following Permission class:

    var Permission = function() {
        var self = this;
    
        self.id = 0;
        self.name = '';
        self.description = '';
    };
    

    [The values of those Permission properties aren’t going to change here, so no need to make those observables.]

    Now, given all that background, here’s how I bound the checkboxes so that the proper checkboxes are checked:

    <ul data-bind="foreach: $root.permissions">
        <li>
            <label>
                <input type="checkbox" 
                       data-bind="value: id, checked: $parent.userPermissions" />
                       &nbsp;<span data-bind="text:name" />
            </label>
        </li>
    </ul>
    

    This code appears within the with: currentUser block, so $parent is currentUser

    Here’s the link to the fiddle that contains my solution: http://jsfiddle.net/jimmym715/eByAa/

    Oh, and I added the following code to the view to confirm that userPermissions is getting updated with each check/uncheck of a checkbox.

    I hope this solution suits your needs. Let me know if you have any questions.

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

Sidebar

Related Questions

This is my first attempt to create a GUI in MATLAB. I haven't been
First attempt to use this cool site - after searching for 2 hours: So
First day and first attempt at using Scala - so go easy on me!
This is my first attempt at responsive design, so I'm keeping it simple. I
This is my first attempt to write shorthand if statements however am befuddled by
Because this is my first attempt at an extension method that seems quite useful
this if my first attempt at using streaming for WCF, and I am struggling
Here is my first attempt at validating XML with XSD. The XML file to
Consider my first attempt, a simple type in F# like the following: type Test()
this is my first attempt at a responsive design so excuse me if this

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.