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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:05:13+00:00 2026-06-04T19:05:13+00:00

I am building an application with Knockout and find it very useful. Although, I

  • 0

I am building an application with Knockout and find it very useful.
Although, I have a problem with getting multidimensional array (object) observable.

At the moment I am using following structure:

    self.form = ko.observableArray(ko.utils.arrayMap(initialData, function(section) {
        var result = { 
            name : section.name, 
            code : section.code, 
            type : section.type, 
            fields: ko.observableArray(section.fields) 
        };
        return result;
    }));

It works well, but I can’t get it working if the initialData is more than two levels.
I tried something like

    self.form = ko.observableArray(ko.utils.arrayMap(initialData, function(block) {
        var result = { 
            name : block.name, 
            code : block.code, 
            type : block.type, 
            sections: ko.observableArray(ko.utils.arrayMap(block.sections, function(section) {
                var result = { 
                    name : section.name, 
                    code : section.code, 
                    type : section.type, 
                    fields: ko.observableArray(section.fields) 
                };
                return result;
            }))
        };
        return result;
    }));

The final array structure looks good, but knockout doesn’t updates DOM when I am doing push to sections array:

    self.addField = function( section ) {
        field = {
            code: uid(),
            name: "New Field",
            value: '',
            type: section.type
        };
        section.fields.push(field); 
    };

I also tried a knockout.mapping.js plugin (is that a right approach?) looks good first, but after a push in the function above I have my new field element not observable, just object.

The plugin doumentation says:

// Every time data is received from the server:
ko.mapping.fromJS(data, viewModel);

But I am not sure that it is my case.

If anyone has any ideas, it would be much appreciated.

Thanks.

UPD:
It is not a problem to make 1st and 2nd levels observable, problem is to go deeper.

Here is an example of initialData:

var blocks = [
    {
        "name" : "",
        "sections" : [
            {
                "name" : "Section 1",
                "fields" : [
                    {
                        "name" : "Field A",
                        "type" : "checkbox",
                        "code" : uid()
                    }
                ]
            }
        ]
    }
];

HTML

<div data-bind='template: { name: tpl-form-field-checkbox, foreach: fields }'></div>
<button class="btn addField" data-bind="click: $root.addField">Add</button>

<script type="text/html" id="tpl-form-field-checkbox">
    <input type="text" name="" value="<%= name %>" /> <br/>
</script> 
  • 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-04T19:05:17+00:00Added an answer on June 4, 2026 at 7:05 pm

    The mapping plugin is the best way to go. It will automatically map your objects into observables and observableArrays, so you don’t have to do it manually.

    Here is a simple fiddle that may give you some pointers: http://jsfiddle.net/jearles/CGh9b/

    In this example I create a tree structure and them allow you to add a new entry. You can see that I am able to continue to add at increasingly deeper levels with no problem, and because the names are observable they can be changed.

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

Sidebar

Related Questions

I am beginner in C# programming. I have encountered small problem during building application
I'm building a MVC application which has a heavy client side scripting using Knockout,JQuery
I am building an application and I am trying to keep it object oriented.
I'm building application using pop-ups. I'm getting new information with Ajax in the main
While building my application with relational tables I ran into the following problem :
I have application building using third party apis, j2me apis,application code distributed in various
I'm working with a new application at work that we're building out using Knockout.js
Building an application to calculate metrics on Service Level Agreements. I have access to
When building an application, is there any meaningful difference between the idea of Find
i'm building java application and suddenly i found problem with compilation: [ERROR] Failed to

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.