You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
Will get:
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 integer3
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 getnull
for its index, so it use0
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.
The text was updated successfully, but these errors were encountered: