knockout.mapping icon indicating copy to clipboard operation
knockout.mapping copied to clipboard

bug of optimizedKeys

Open WindieChai opened this issue 9 years ago • 0 comments

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.

WindieChai avatar Oct 31 '16 08:10 WindieChai