knockout.mapping
knockout.mapping copied to clipboard
Key callback is being fired twice
Given the following code snippet:
var data = {
name: 'Scott',
children: [
{ id : 1, name : 'Alice' },
{ id : 2, name : 'Bob' },
{ id : 3, name : 'Chris' },
{ id : 4, name : 'Robert' }
]
}
var mapping = {
'children': {
key: function(data) {
console.log(data.id);
return ko.utils.unwrapObservable(data.id);
}
}
}
var viewModel = ko.mapping.fromJS(data, mapping);
Which is taken from the documentation, with slight modifications.
Expected result in console would be: 1 2 3 4
Actual result is: 1 2 3 4 1 2 3 4
.
jsFiddle: http://jsfiddle.net/losnir/a2qMQ/
As mentioned in the title, the key
callback is being fired twice.
The culprit seems to be on line 570 (filterArrayByKey
, 1st fire) and on line 582 (keyCallback(unwrappedRootObject[i])
, 2nd fire).