Comments (5)
The result is kind of unexpected. It is by design that the mapping plugin cannot handle arrays with duplicate objects (see the key
callback part of the mapping plugin documentation).
For an array of primitives like you have here, I guess duplicates should be allowed.
Is your use-case with an array of primitives like in your example, or are you using objects?
from knockout.mapping.
The example I posted is a simplification but yeah, it matches my use case almost exactly. Here's a closer example:
data = {
...
properties: {
arrayKey: ["1", "1", "1", "2"]
}
}
I'm grabbing a bunch of data via api, and the array that I noticed this happening on is one of a handful of properties that's stored in a serialized object. Until now we've been able to infer what we need from the length of the array and it's contents. It should be possible to rework things on the back-end and add a key, but being able to bind the existing array would be much easier for now.
from knockout.mapping.
Ok! Well, if you have the time to create a pull request that would be highly appreciated :) Otherwise it may take a few days before I can get around to fixing it.
from knockout.mapping.
Alright. I'll see what I can do.
from knockout.mapping.
I haven't had a lot of time to look at this, but I've found that the culprit is line 305:
var index = ko.utils.arrayIndexOf(ko.utils.unwrapObservable(rootObject), item);
What happens is ko.utils.arrayIndexOf() returns the first matching index, which means that when the next line fires...
newContents[index] = mappedItem
...the same index gets used, so that item in the newContents array gets written over again and again. But since the mapping plugin is using ko.utils.arrayIndexOf I'm not sure how to proceed.
from knockout.mapping.
Related Issues (20)
- mapping fails if value = "constructor" HOT 2
- Is there a way to update the nested properties of the items of an ObservableArray? HOT 1
- Method visitPropertiesOrArrayEntries is doing unnecessary iterations on updateViewModel because the wrong variable is being used to check against ignored properties.
- Mapping not saved when data is an array HOT 1
- Mapping doesn't work when properties listed in different order HOT 4
- Empty observe array in mapping options creates observables from all properties HOT 1
- ko.mapping.toJSON to implement JSON formatting param like ko.toJSON
- Calling fromJS to amend an existing model with an ObservableArray fails
- NuGet package install directory
- Questions about Knockout Mapping HOT 10
- The "create" handler does not work with non-array properties HOT 1
- Create handler causes mapping to evaluate pureComputed HOT 1
- Suggestion: Safely update mapping when property in new object happens to be null
- mapping partial model into existing viewModel
- [Question] is arrayChanged part of the public api?
- objectLookup() + "watch" + Firefox = hilarity
- bug of optimizedKeys
- optionsCaption causes bound "value" to be deleted
- Doesn't seem to work with KO 3.4.2 HOT 1
- Having redudant data passed to an object makes it so the second reference of the same object is not updated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout.mapping.