Skip to content

bug of optimizedKeys #218

@WindieChai

Description

@WindieChai

I'm trying to use ko.mapping to map a mix-typed array, then I found the result is very weird.
For example, following code:

ko.mapping.fromJS([1,2,3,'3'])()

Will get:

["3", 2, undefined × 1, "3"]

I just spent a little time on this issue and I found it is caused by the optimizedKeys determination starting from line 580 of knockout.mapping.js.
Just say, both string '3' and integer 3 will be used as key of a object (so there will be only one property with key '3'); then this key will be used to determine the index of the member; one of the members will get null for its index, so it use 0 by default and the correct position of that member will be undefined.

Currently I convert my array to an object array to avoid this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions