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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:35:00+00:00 2026-06-17T22:35:00+00:00

I have got a task to do knockout.js. Here i have a model employee

  • 0

I have got a task to do knockout.js. Here i have a model employee with fields name,country and state. While editing this i want to save it.But when i doing this i can’t save it.
My edit page is

<%= javascript_include_tag "knockout-2.2.0" %>
<script>
$(document).ready(function() {


    // Here's my data model
        var ViewModel = function(){
            this.country = ko.observable();
            this.state = ko.observable();
            this.name = ko.observable();
            this.fullName = ko.computed(function() {
                return this.country() + " " + this.state();
                 }, this);

            this.save = function(){

                var jsonData = ko.toJSON(ViewModel);
                alert("Could now send this to server: " + JSON.stringify(jsonData));

                $.ajax({
                    url: '/employees/<%=@employee.id%>',
                    dataType: 'json',
                    type: 'PUT',
                    data: { total_changes: JSON.stringify(jsonData) },

                    success: function(data){
                        alert("Successful");
                    },
                    failure: function(){
                        alert("Unsuccessful");
                    }
                });
            }
};


        ko.applyBindings(new ViewModel());

});
</script>


<%= form_for(@employee) do |f| %>
  <% if @employee.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@employee.errors.count, "error") %> prohibited this employee from being saved:</h2>

      <ul>
      <% @employee.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br />
    <input data-bind='value: name, valueUpdate: "afterkeydown"' />
  </div>
 <div class='label'>
        <%= f.label :country %><br />
        <input data-bind='value: country, valueUpdate: "afterkeydown"' />
  </div>
  <div class="field">
    <%= f.label :state %><br />
    <input data-bind='value: state, valueUpdate: "afterkeydown"' />
  </div>

<p>Name:
<span data-bind="text: name"> </span></p>

<p>Country:
<span data-bind="text: country"> </span></p>

<p>State:
<span data-bind="text: state"> </span></p>
 <button data-bind='click: save'>Submit</button>
  </div>
<% end %>

I cannot get the json object.

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

    Try using

    var jsonData = ko.toJSON(this); 
    

    instead of

    var jsonData = ko.toJSON(ViewModel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a task to do knockout.js in ruby on rails. I want
i have got 3 tables: Event, task, task_handler. EVENT: event_id|name TASK_HANDLER: event_id|task_seq|handler TASK: event_id|task_seq|script
This is just a simple async task but I have always got strange compiler
I have got this function that returns a constant..Here is my class and function:
Lately i have got a task to import a 3D model which is created
I am new in Java and have got as a task to find out,
Have got an NSString *str = @12345.6789 and want to find out if there
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have got two pages. example.com/php.com and example.com. I use this function to set
I have this error when i perform the following task, results = db1.executeSelectCommand(siteSql, (),)

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.