Open ghost opened 8 years ago
I'm having essentially the same issue. Here's some sample code:
var objectMapper = require("object-mapper")
var orig = {
foo: [
{"name": "a", "things": ["a1", "a2"]},
{"name": "b", "things": ["b1", "b2"]}
]
}
var map = {
"foo[].name": "bar[].label",
"foo[].things[]": "bar[].values[]"
};
var newOb = objectMapper(orig, map);
...which gives us this:
bar: [{
label: "a",
values: [
["a1", "a2", "b1", "b2"]
]
},
{
label: "b"
}
]
...but what's required is this:
bar: [{
label: "a",
values: ["a1", "a2"]
},
{
label: "b",
values: ["b1", "b2"]
}
]
+1 I am facing the same issue. Any idea what the right usage is or possible fix?
So this seems to work OK in master, but the 3.0.1 that's tagged in npm does not work (see the test case in my fork). Can you tag a new version so this fix is included?
+1. I'm seeing the same issue. Any way we can get a new version tagged?
Was this array of array issue ever resolved?
@briandelancey were you able to get this to work? i have a very similar structure thats still seems to produce similar output as your example.
@jalleyne no. My mapping requirements quickly became more complex and I ended up rolling my own solution entirely.
This issue is resolved for me by taking the code from GitHub rather than getting it from NPM.
Hey everyone. So sorry for taking so long for this. If anyone wants to help maintain, lmk.
object-mapper@3.1.0 is on npm
If this resolves this issue, please close it if you can or let me know.
@wankdanker I've tried out both 3.0.1
and 3.1.0
with the example provided above and the result is still incorrect as far as I can see.
var objectMapper = require("object-mapper")
var orig = {
foo: [
{"name": "a", "things": ["a1", "a2"]},
{"name": "b", "things": ["b1", "b2"]}
]
}
var map = {
"foo[].name": "bar[].label",
"foo[].things[]": "bar[].values[]"
};
var newOb = objectMapper(orig, map);
{
"bar": [{
"label": "a",
"values": [
["a1", "a2", "b1", "b2"]
]
}, {
"label": "b"
}]
}
{
"bar": [{
"label": "a",
"values": [
[
["a1", "a2"],
["b1", "b2"]
]
]
}, {
"label": "b"
}]
}
A corresponding code change would be needed in SetKeyValue
I believe.
@midknight41 2 notes:
The mapping of the sub array should not have [] at the end:
BAD:
"foo[].things[]": "bar[].values[]"
GOOD
"foo[].things[]": "bar[].values"
https://runkit.com/nocopy/59fcc300c151150011c902c4
No matter which way you try and structure it, it doesn't seem to work if the initial object is array of objects itself:
var orig = { // could never get this structure to map / work.
{"name": "a", "things": ["a1", "a2"]},
{"name": "b", "things": ["b1", "b2"]}
}
I am using version 5.0.0. I am still facing the same issue.
Added a test case. Works in my branch.
I am still facing issue with 5.0.0 downloaded through npm. Is this fixed?
Hey :) Thanks for such a good lib!
I have a problem when i do this:
it outputs this:
The problem is with discounts:
I may have misunderstood the syntax, I tried different ways and it doesn't work :s Have you ever seen this ? Thanks! ;)