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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:51:26+00:00 2026-06-05T12:51:26+00:00

I’m new to Knockoutjs. I have a observable array of Users. Here is my

  • 0

I’m new to Knockoutjs. I have a observable array of Users. Here is my User model:

function User(data) {
        this.NameID = ko.observable(data.NameID);
        this.UserID = ko.observable(data.UserID);
        this.InTime = ko.observable(data.InTime);
        this.OutTime = ko.observable(data.OutTime);
        this.Notes = ko.observable(data.Notes);
        this.StatusID = ko.observable(data.StatusID);
        this.Status = ko.observable(data.Status);
        this.InOut = ko.observable(data.InOut);
        this.Name = ko.observable(data.Name);
        return this;
    }

Then in my view model I make an array of Users. Doing the foreach in my view to show all the users in a table is easy, but I want to make a form so the current user can change the his varibles.
I’m using session variable to set the UserID. Then I’m using the ko.utils.arrayFirst to find the current user from the array. I feel like i’m not making any sense here. Is there anyway to make a form to access a User? like below:

function UserViewModel() {
        var self = this;
        self.users = ko.observableArray([]);
        self.statuses = ko.observableArray([]);
        self.currentUser = ko.utils.arrayFirst(self.users(), function (user) {
                return user.UserID() == @HttpContext.Current.Session["UserID"];
        });
}

Then in my view make a form(I’m using twitter-bootstrap) like this:

       <form class="well form-horizontal">    
        <div class="control-group">
            <label class="control-label" for="Statuses">
                Status</label>
            <div class="controls">
                <select id="Statuses" data-bind="options: statuses, optionsValue: 'StatusID', optionsText: 'Stat', value: currentUser.StatusID">
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="InTime">
                In:</label>
            <div class="controls">
                <input id="InTime" data-bind="value: currentUser.InTime" class="span1" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="OutTime">
                Out:</label>
            <div class="controls">
                <input id="OutTime" data-bind="value: currentUser.OutTime" class="span1" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="Notes">
                Notes</label>
            <div class="controls">
                <textarea id="Notes" data-bind="value: currentUser.Notes" /></textarea>
                 <p><span style="text-align:center;"><a id="chg" class="btn btn-primary" >Update</a></span></p>
            </div>
        </div>   
       </form>

Please comment if i’m not making any sense or if you need more information to help solve my problem.
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-05T12:51:29+00:00Added an answer on June 5, 2026 at 12:51 pm

    What kind of error are you getting? It looks to me like your currentUser property will get set in the constructor while the arrays look like they are empty still for one thing, maybe you’re just not showing where the users are populated. Another is that you are just setting it once, you could create an observable for the user id and use a computed to find the matching user, then you can easily change the user by changing the ID later or after you set the users:

    self.currentUserId = ko.observable(@HttpContext.Current.Session["UserID"]);
    self.currentUser = ko.computed(function() {
        return ko.utils.arrayFirst(self.users(), function (user) {
                return user.UserID() == self.currentUserId();
        });
    });
    

    The currentUser should then be set correctly when you update your array or the currentUserId observable. If the user is an observable, you will need to call it as a function, or use the with binding on your form:

    <input id="InTime" data-bind="value: currentUser().InTime" class="span1" />
    
    <form data-bind="with: currentUser">
    <input id="InTime" data-bind="value: InTime" class="span1" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I want to construct a data frame in an Rcpp function, but when I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.