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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:51:33+00:00 2026-06-18T19:51:33+00:00

I am trying to add a computed to a child view model which is

  • 0

I am trying to add a computed to a child view model which is populated using the Knockout mapping. When I break in I see the role array populated correctly in the javascript array but in my view model the observable array is always length 0.

Here is a jsfiddle that shows it. Any help on what i am missing would be appreciated.

http://jsfiddle.net/spbrogan/aREpY/

Here is the child view model

var userModel = function(data) {
    data.createDate = new Date(data.createDate);

    ko.mapping.fromJS(data, {}, this);


    this.isAdmin = ko.computed(function() {
        var admin = false;
        ko.utils.arrayForEach(this.role(), function(role) {
            if(role.name == "Admin") {
                admin = true;
             }
         });
         return admin;
    }, this);
} //close userModel

Thanks

  • 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-18T19:51:34+00:00Added an answer on June 18, 2026 at 7:51 pm

    After the mapping has run it creates observables from your JS – not just the root object, but all properties inside it. An observable is a function, so you need to access name using the () form:

    ko.utils.arrayForEach(this.role(), function(role) {
        if(role.name() == "Admin") {
             admin = true;
        }
    });
    

    Here is an updated fiddle: http://jsfiddle.net/aREpY/41/

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

Sidebar

Related Questions

Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a class object into a List using reflection, but when invoking
I am trying to add a registry key which will allow my program to
I have a method where I am trying to add a child to my
I'm trying to add an option for my Windows Froms application which will allow
Here is my webgrid .I am trying to add a column EndDate which displays
I am trying to find which element(index) of a multidimensional signal is computed at
I am trying to create a persisted computed column using CASE expression: ALTER TABLE
I'm trying to add a new nova-compute node (KUubuntu 12.04) to my single node
I'm trying add data triggers to the default combobox style so each text item

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.