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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:10:23+00:00 2026-06-11T22:10:23+00:00

I have a view model setup with an observable array of user objects. The

  • 0

I have a view model setup with an observable array of user objects. The add/remove of items are working correctly but how do I update items? I can find the values using the ko indexOf function.

function User( username, date_inactive, date_active ) {
    this.username = username;
    this.date_active = date_active;
    this.date_inactive = date_inactive;
};  

User.prototype.inactivateMe = function() {
    json_responses.push( this );
    $.getJSON( "url" + this.username, function( json ) {
        original = json_response.pop();
        //do update here
    });
};

userModel = [  ], //Where the loaded usernames are stored. 

viewUserModel = {
    users: ko.observableArray(userModel)
    //.......

    //This is how I'm adding users to the array.
addUser: function () {
    $.getJSON( "url", 
    { username: usern }, 
        function( json ) { 
            if( json.STATUS != undefined && json.STATUS == 'success' ) {
                newuser = new User( json.USERNAME, json.DATE_ACTIVE, json.DATE_INACTIVE  );
                viewUserModel.users.push( newuser );            
            }
        }
    });
    }

The values of viewUserModel.users are pushed into the array from a server json reponse.

I want to be able to update the date_active and date_inactive values when the user clicks a button and the server responses with success.

My setup is an adaption from http://net.tutsplus.com/tutorials/javascript-ajax/into-the-ring-with-knockout-js-the-title-fight/

  • 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-11T22:10:24+00:00Added an answer on June 11, 2026 at 10:10 pm

    An observable array only tracks changes made to the array (such as pushes and pops), not the data itself. You will need to make date-active and date_inactive observables as @Ianzz has specified.

    function User( username, date_inactive, date_active ) {
        this.username = username;
        this.date_active = ko.observable(date_active);
        this.date_inactive = ko.observable(date_inactive);
    };
    

    Afterwards in your html, do something such as

    <div data-bind="foreach: Users">
        <input data-bind="value: date_active"/>
        <input data-bind="value: date_inactive"/>
    <div>​
    

    See fiddle for full example.

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

Sidebar

Related Questions

I have a parent-child view model object structure set up and need to update
I have a simple model setup in my Ruby on Rails app. (User {name,
When I have a View Model setup with an ImportingConstructor that takes a single
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
I have a view model coming from the server as json like this {
I have a view model that looks like this public class ViewModelRound2 { public
I have a view model with an Email address property and a Confirm Email
I have this view @model IEnumerable<ViewModelRound2> ... <snip> ... @{ using (Html.BeginForm(new { round1Ring3Bids
I have a view model with a couple of properties that are not displaying
I have a view model with a property Fields which is an ObservableCollection<FieldVM> .

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.