Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key callback is being fired twice #194

Open
losnir opened this issue Jun 17, 2014 · 0 comments · May be fixed by #201
Open

Key callback is being fired twice #194

losnir opened this issue Jun 17, 2014 · 0 comments · May be fixed by #201

Comments

@losnir
Copy link

losnir commented Jun 17, 2014

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).

@ghost ghost linked a pull request Nov 11, 2014 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant