Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Can we see your knockout model? Is the subgroup an observableArray()? if not it won't update.</p> <p>Edit:</p> <p>The way I have typically dealt with sub arrays is by manually mapping the top level observableArray, then creating a second observableArray for the subArray. Knockout has some handy utilities in the <code>ko.utils</code> namespace that we can use, <a href="http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html" rel="nofollow">knockout utils</a>. The ko.utils function <code>ko.utils.arrayForEach</code> takes an array and returns an array, and takes a function that will get called forEach item in the original array. This is where we can do the mapping.</p> <pre><code> var dataFromServer = ko.utils.parseJson(JSONdataFromServer); //now that we have a javascript object we can pass that into ko.utils.arrayForEach viewModel.viewRoles = ko.utils.arrayForEach(dataFromServer, function(viewRole) { var newRole = { groups : ko.observableArray(ko.utils.arrayForEach(viewRole.group, function(group) { var newGroup = { //map the properties from your JSON group to this object }; return newGroup; })), //map any other properties from your JSON role to this object }; return newRole; }); </code></pre> <p>Once we have the JSON data as a javascript object we can pass it into ko.utils.arrayForEach. We pass ko.utils.arrayForEach the javascript array and a function that it will call for each item in that array, which are your roles. The first function creates a new Role object with the sub array which is also an observableArray() called groups.</p> <p>Let me know if any of that is confusing I can try and explain more. Also I haven't actually run any of this code so there may be errors.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload