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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:36:19+00:00 2026-06-09T12:36:19+00:00

I have a basic table set up using knockout, but I was wondering if

  • 0

I have a basic table set up using knockout, but I was wondering if there is any way to edit/save a single record, rather than having to save the entire view model every time a change is made? Here’s my code…

<tbody data-bind="foreach: movies">
    <tr> 
        <td data-bind="text: title"></td>
        <td data-bind="text: releaseDate"></td>
        <td data-bind="text: genre"></td>
        <td data-bind="text: price"></td>
        <td><input type="button" value="Edit" id="edit"/></td>
    </tr>
    <tr class="editable"> <!-- hide this initially, only show when edit button is   clicked -->
        <td><input id="titleInput" data-bind="value: title" /></td>
        <td><input id="releaseDateInput" data-bind="value: releaseDate" /></td>
        <td><input id="genreInput" data-bind="value: genre" /></td>
        <td><input id="priceInput" data-bind="value: price" /></td>
    </tr>
 <!-- save button/form or something here containing ONLY this record -->

</tbody>
</table>


<script type="text/javascript">

function Film(data) {
    this.title = ko.observable(data.Title);
    this.releaseDate = ko.observable(data.ReleaseDate);
    this.genre = ko.observable(data.Genre);
    this.price = ko.observable(data.Price);
}

function MovieListViewModel() {
    var self = this;
    self.movies = ko.observableArray([]);
    self.title = ko.observable();
    self.releaseDate = ko.observable();
    self.genre = ko.observable();
    self.price = ko.observable();

    $.getJSON("/Movies/GetAllMovies", function (allMovies) {
        var mappedMovies = $.map(allMovies, function (movie) { return new Film(movie)    });
        self.movies(mappedMovies);
    });
}

ko.applyBindings(new MovieListViewModel());

Any thoughts? 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-09T12:36:21+00:00Added an answer on June 9, 2026 at 12:36 pm

    Actually, through the magic of binding contexts, this is quite easy!

    1. Step one. Place the following element anywhere inside your foreach template.

      <button data-bind="click: $root.saveMovie">Save</button>
      
    2. Step two. Add the saveMovie method to your viewModel

      self.saveMovie = function(movie) {
          $.ajax({
              type: "POST",
              url: "/someurl",
              dataType: "json",
              contentType: "application/json",
              data: ko.toJSON(movie),
              success: function(result) {
                  //...
              }
          });
      }
      

    The movie variable will contain the item of your foreach loop! Why? Because in Knockout, we have the amazing feature called binding contexts:

    A binding context is an object that holds data that you can reference
    from your bindings. While applying bindings, Knockout automatically
    creates and manages a hierarchy of binding contexts. The root level of
    the hierarchy refers to the viewModel parameter you supplied to
    ko.applyBindings(viewModel). Then, each time you use a control flow
    binding such as with or foreach, that creates a child binding context
    that refers to the nested view model data.

    http://knockoutjs.com/documentation/binding-context.html

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

Sidebar

Related Questions

I have a pretty standard table set-up in a current application using the .NET
I have a very basic Table structure to be placed in middle/center of the
I have a fairly basic data.table in R, with 250k rows and 90 columns.
I have a very basic mysql table called memberships, that tracks which people belong
I have a basic string with holds a html table. The table looks like
I have this table, which can be seen as a basic custom gantt chart:
I have a messaging system (very basic) that has a table like this: **MESSAGE_ID**
I'm working on a very basic shopping cart system. I have a table items
I am using LINQ to SQL with single table inheritance for an audit log.
I am using visual basic 6. I have a button created which when pressed

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.