angeliquekom / vue-json-to-csv

A Vue.js 2 component for transform and download a json in csv format
MIT License
35 stars 9 forks source link

When binding json-data to a data property that is an array of objects, csv is showing extra column #2

Closed sam-n-bell closed 6 years ago

sam-n-bell commented 6 years ago

When I bind json-data to a data property that is an array of objects and then export the csv, I'm seeing an extra column with the label obj present. Each row in that column under the label is [object Object].

Example:

In my template: <vue-json-to-csv :json-data="test_export" :csv-title="'transactions'">

In the data function of my component: data: function () { return { test_export: [{name: 'Joe', surname: 'Roe'}, {name: 'Joe', surname: 'Doe'}]};},

And result when exporting:

screen shot 2018-07-20 at 11 39 28 am

This is only happening when binding to an array in my component's data. If I have the json-data binded to in-line (not sure what the correct terminology is) data like in your examples, it works perfectly, but that isn't feasible for what I'm trying to do.

angeliquekom commented 6 years ago

Thank you very much for your bug report! This error was caused due to handling a vue.js object as a normal object (observer object was involved at the parsing of values). I tried to get only the values needed using destructuring assignment (https://github.com/vuejs/Discussion/issues/292). I have published a new version at NPM, 1.0.5. Please let me know if that solves your problem.

sam-n-bell commented 6 years ago

Fix looks like it works, thank you for the response