Closed KhalidH82 closed 3 years ago
fields[].value can also be a function, see https://github.com/zemirco/json2csv/tree/v5#example-fields-option
Thanks for your quick response! I'm trying to access a field from an object. I've used dot notation and brackets but was unsuccessful. Does this library support this?
{
label: "Formatted sale price",
value: (row) => "from £".concat(**_row.price_from.default_**),
},
Thanks again 🙏
I'd have to see a sample of you data to answer that, but generally yes.
Here is a sample of the field I'm looking to access. "price_from": { "default": 20 },
I'm looking to concat "from £", but in the CSV it shows... "from £[object Object]"
This is the code used... { label: "Formatted sale price", value: (row) => "from £".concat(_row.pricefrom.default), },
Let me know if this helps.
Looks like the output is not what is expected I recommend console.log(row.price_from.default)
to see what you get back. Seems like default
is an object, not a string.
Looks like the output is not what is expected I recommend
console.log(row.price_from.default)
to see what you get back. Seems likedefault
is an object, not a string.
Thanks for your help and support!
Hi, I'm looking to add some data transforms to the cell values in my CSV. I've created a function that receives the data item and returns the item.