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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:47:30+00:00 2026-06-14T06:47:30+00:00

I am having trouble iterating over my json data with knockout. My view model

  • 0

I am having trouble iterating over my json data with knockout.
My view model looks like :

var ViewModel = function () {
    var self = this;
    self.Summary = ko.observableArray();
    $.getJSON('some api url', function(result) {
        ko.mapping.fromJS(result, {}, self);
    });
}
ko.applyBindings(new ViewModel());    

My JSON data looks like :

{
Summary: {
    Details: [
        {
            Name: "Foo",
            Id: 1,
            Detail: "Some Data"
        },
        {
            Name: "Bar",
            Id: 2,
            Detail: "Another Data"
        }
    ],
    SummaryOverview: "BlahBlah",
    AnotherObject: [
        {
            Name: "My Name"
            AnotherChildObject: [
                {
                    name:"some name"
                }
            ]
        }
    ]
}

}
My question is do I iterate thru my data this way:

<div data-bind="foreach: Summary">             
    <div data-bind="text: Details.Detail"></div>
</div>

OR

<div data-bind: "foreach: Summary.Details">
    <div data-bind="text: Detail"></div>
</div>

How do I display the Detail? The HTML above is not working for me.
Thank you very much!!

  • 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-14T06:47:32+00:00Added an answer on June 14, 2026 at 6:47 am

    The problem with ko.mapping is that your observables will be replaced with new observables. To clarify, the Summary, which is an observableArray, will be replaced by a new observableArray by ko.mapping.

    There are two ways to remedy this. The first alternative is to wait with the applyBindings until the real array has been created:

    var ViewModel = function () {
        var self = this;
        // no need to set the array, it will be overwritten anyway
        // self.Summary = ko.observableArray();
    }
    
    var vm = new ViewModel();
    $.getJSON('some api url', function(result) {
        ko.mapping.fromJS(result, {}, vm);
        ko.applyBindings(vm);
    });
    

    Alternative 2 is to bootstrap the viewmodel with initial (empty) data. If you apply ko.mapping on an empty array, the next call to ko.mapping will update the existing array rather than overwrite it. Like so:

    var ViewModel = function () {
        var self = this;
        var init = { Summary: [] };
        ko.mapping.fromJS(init, {}, self);
    
        $.getJSON('some api url', function(result) {
            ko.mapping.fromJS(result, {}, self);
        });
    }
    
    ko.applyBindings(new ViewModel());
    

    I usually go with alternative 2. Alternative 1 will cause a delay before ko.applyBindings is called, which might cause some UI flicker (and unwanted elements may be visible, etc).

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

Sidebar

Related Questions

I'm having a bit of trouble iterating and retrieving width() values. $(.MyClass).each( function ()
I'm having trouble iterating in reverse over a map in GCC C++. When I
I'm having trouble with iterating and getting the values within a collection of arrays
I'm using KVC to iterating through a few views. Having trouble setting BOOL properties:
Having trouble with each function... Will try to explain by example... In my code,
I'm relatively new to JavaScript and I've been having trouble pushing data into an
I am having trouble understanding how to best use Core Data to solve this
I am having trouble clicking or interacting with some page elements. They seem like
Having trouble with an .htaccess file on WAMP. Works on the live server, but
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc

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.