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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:17:50+00:00 2026-06-10T12:17:50+00:00

I have a web API which successfully returns an array of blog posts in

  • 0

I have a web API which successfully returns an array of blog posts in JSON format:

[{"ID":1,"Title":"First Blog Post","Body":"Some Content"},{"ID":2,"Title":"Second BlogPost","Body":"Some other content"}]

For exercise purposes, I want to display all posts in a list using Knockout.js.

Here is my code:

<script>
$(document).ready(function () {

    function AppViewModel() {
        var self = this;

        self.posts = ko.observableArray([
        { Title: 'Default Title', Body: 'Default Body' },
        ]);

        $.getJSON('api/posts', function (data) {
            ko.mapping.fromJSON(data, {}, self.posts);
        });

    }

    ko.applyBindings(new AppViewModel());

});

My bindings:

<tbody data-bind="foreach: posts">
                <tr>
                    <td data-bind="text: Title"></td>
                    <td data-bind="text: Body"></td>
                </tr>
</tbody>

My table shows up empty, it’s not showing the JSON data for some reason…

ANSWER: I had to change fromJSON to fromJS and it works! Thanks so much for your help everyone

  • 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-10T12:17:51+00:00Added an answer on June 10, 2026 at 12:17 pm

    In your case you need to specify the update target for the mapping.

    From the Knockout Mapping plugin documentation:

    If, like in the example above, you are performing the mapping inside
    of a class, you would like to have this as the target of your mapping
    operation. The third parameter to ko.mapping.fromJS indicates the
    target. For example,

    ko.mapping.fromJS(data, {}, someObject);
    

    So in your case:

    $.getJSON('api/posts', function (data) {
            ko.mapping.fromJSON(data, {}, self.posts);
        });
    

    A working JSFiddle

    Also note that that the property names are case sensitive and they should match in the JSON and in your viewmodel and bindings. e.g you retrive "Title" but you are using title

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

Sidebar

Related Questions

I have a web site with an API which publishes the information using JSON.
Using the ASP.NET Web-Api, I have the following POST setup in my controller. When
Am using Lucene API in my web portal which is going to have 1000s
I have a Web API controller action which has a parameter of type CommandMessage.
Is there any simple Web API which returns album art as an image, just
I have an ASP.NET MVC 4 application which uses the new ASP.NET Web API.
I have build an APi which is a WCF Service. In the web.config for
I have developed an ASP.NET Web API which response like this: <ArrayOfMyData> <MyData> <Id>1</Id>
I have an asp.net web api application which is acting as a Relay to
I am currently working on MVC4 SinglePage Application. I have a Web Api method

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.