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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:11:52+00:00 2026-06-17T05:11:52+00:00

Been getting into Knockout and and slowly getting used to it. Trying to use

  • 0

Been getting into Knockout and and slowly getting used to it. Trying to use it in a new project, but am having a hard time getting things lined up to work. While I understand and can do simple examples (simple form with text boxes bound to ko.observables, or a table or list bound to a ko.observableArray), I can’t get the syntax right for a combination, especially if I want to convert the data to JSON format in order to transmit it, via a webservice, to be saved into a database.

Basically it’s a data entry form, with some text entry boxes, then a list of items (think company information + a list of it’s employees).

I have a sample Fiddle here: http://jsfiddle.net/rhzu6/

In the saveData function, I just don’t know what to do to get the data packaged. Doing ko.toJS(self) just shows “Object”.

I tried defining the data as objects, but quickly got lost:

function Company(CompanyName, ZipCode) {

    var self = this;
    self.ZipCode = ko.observable(ZipCode);
    self.CompanyName = ko.observable(CompanyName );
    self.Employees = ko.observableArray();
}

function Employee(FirstName, LastNameB) {
    var self = this;
    self.FirstName = ko.observable(FirstName);
    self.LastName = ko.observable(LastName);
}

Then the ViewModel looked like:

function viewModel() {
    var self = this;
    self.Company = ko.observable(); // company?
    self.Employees = ko.observableArray(); // ?
}

But ran into the same issue. And also had binding problems – data-bind:”value: CompanyName” threw an exception saying it didn’t know what CompanyName was…

Color me stumped. I’m sure it’s something easy that I’m just missing.

Any and all help would be appreciated!

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-17T05:11:53+00:00Added an answer on June 17, 2026 at 5:11 am

    You are looking for ko.toJSON which will first call ko.toJS on your ViewModel and afterwards JSON.stringify.

    ko.toJS will convert your knockout model to a simple JavaScript object, hence replacing all observables etc. with their respective values.

    I updated your Fiddle to demonstrate.

    For more info, take a look at this post from Ryan Niemeyers blog.

    An alternative is to make use of ko.utils.postJson:

    ko.utils.postJson(location.href, {model: ko.toJS(viewModel) });
    

    Notice the ko.toJS again.

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

Sidebar

Related Questions

I'm having a difficult time getting into using mod_rewrite. I've been at this for
I've been getting into Ruby over the past few months, but one thing that
I have been getting into Unit Testing with Zend Framework. I am getting used
I've been getting stuck into some linq queries for the first time today and
I have been recently getting into iOS development, and I'm trying to build something
So I've been getting into the new C++ using GCC 4.6 which now has
I've been getting into ruby on rails but I've had lots of problems with
When trying to INSERT data into a database table, I've been getting the following
I've been getting into the nitty gritty of the haskell typesystem and trying to
I've been getting into mapkit and corelocation for ios. I'm just trying to display

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.