2017-02-03 32 views
0

我正在做從可觀察模型ko.mapping到js轉換爲具有嵌套可觀察數組的複雜模型如下。ko.mapping.toJS不忽略嵌套可觀察數組

[{ 
"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 }] 

我想忽略嵌套的實體數組。 我想嘗試但不能工作,因爲數組。

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

這不是關於映射 - 這也不適用於嵌套數組,但這是關於忽略不起作用。

有什麼辦法可以做到這一點?

+0

這是不重複的 - 例如看起來一樣,但是這個人是{「忽略」:「Entities.Entity」]不工作。 – jjj

回答

0

我不認爲ignore選項是與點符號兼容。

試試這個:

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

工作過的日子 - 謝謝 – jjj