Search code examples
knockout.jsknockout-mapping-plugin

ko.mapping.toJS Doesnt ignore nested observable array


I am doing ko.mapping from observable model to js conversion for complex model having nested observable array as follow.

[{
"Count": 2,
"CustomerAccountNumber": 874477,
"Entities": [
  {
    "Count": 1,
    "Entity": [
      [object Object]
    ],
    "EntityName": "a",
    "Sum": 3250
  },
  {
    "Count": 1,
    "Entity": [
      [object Object]
    ],
    "EntityName": "b",
    "Sum": 450
  }
],
"Sum": 3700 }, {
"Count": 1,
"CustomerAccountNumber": 996742,
"Entities": [
  {
    "Count": 1,
    "Entity": [
      [object Object]
    ],
    "EntityName": "c",
    "Sum": 5600
  }
],
"Sum": 5600 }]

I want to ignore nested Entity array. I am trying but not working because of array.

ko.mapping.toJS(viewModel.result(), { 'ignore': ["Entities.Entity"] }, this)

this not about mapping - which is also doesn't work for nested array but this is about ignore doesn't work.

is there any way we can achieve this ?


Solution

  • I don't think the ignore option is compatible with dot notation.

    Try this:

    ko.mapping.toJS(viewModel.result(), { 'ignore': ["Entity"] }, this)