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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:20:12+00:00 2026-06-10T11:20:12+00:00

I have trouble understanding how mapping works with knockoutjs. Pretext: I have an API,

  • 0

I have trouble understanding how mapping works with knockoutjs.

Pretext:

I have an API, that returns JSON

I want to map that JSON to a list in my view

javascript:

    var data = JSON.stringify([
        {
            "text": "this be some text"
        },
        {
            "text": "some more text here"
        }
    ]);

    var viewModel = ko.mapping.fromJSON(data);

    var updateData = function(){
        var newData = JSON.stringify([
            {
                "text": "this be some asdfasdfasdf"
            },
            {
                "text": "some more asdfasdfdfdf here"
            }
        ]);

        ko.mapping.fromJSON(newData, viewModel);
    }

    ko.applyBindings(viewModel);

data and newData are in the same format I would be getting my data from API calls. (Just array of objects)

How can i output that data?

<ul data-bind="foreach: whatgoeshere?">
    <li data-bind="text: text"></li>
</ul>

Thanks for explaining to me how this magic works 😉
Have a good day

  • 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-10T11:20:13+00:00Added an answer on June 10, 2026 at 11:20 am

    At first you should use fromJS instead of fromJSON as the last one expects a string that contains a json.

    Another thing is that you should modify your viewmodel like this:

    { arr: [ { name:'text' }, ... ] }
    

    And type arr in your foreach binding.

    If you don’t want to modify your model then you may pass $root to your foreach that points to your model used in ko.applyBindings

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

Sidebar

Related Questions

I have trouble understanding wikipedia API. I have isolated a link, by processing json
I have a little trouble understanding the security bit around JSON, because often things
I'm having trouble understanding the jQuery pushStack function (documented at http://api.jquery.com/pushStack/ ). I have
The idea of MVC itself seems clear to me but I have trouble understanding
I'm having trouble understanding using D3 events and dispatch functions. I have a chart
I have a 64-tap FIR filter whose output format I am having trouble understanding.
I have trouble figuring out why a simple division like this one always returns
I have trouble doing this... You may want to get the same result as
I have trouble shooting at file download problem. In Chrome, the download works fine.
I have trouble understanding the following thing: in my localized application I have an

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.