NgCSV无法生成CSV文件

时间:2015-10-26 22:55:40

标签: javascript angularjs csv object

所以我有一个应用程序应该POST到API然后我接受该响应,从中生成链接,并将其导出到看起来像这样的CSV文件。

enter image description here

我在这里通过以下功能这样做。

scope.exportWidget = function () {


            var query2 = QueryService.getQuery();
            query2.query.start = 0;
            query2.query.count = 20;
            query2.query.sortBy = 'date';
            query2.query.sortOrder = 'desc';
            delete (query2.query.temporal);
            delete (query2.query.geospatial);
            query2.count = 20;
            query2.start = 0;


            DataService.exportTable(query2).then(function (res) {
                var data = angular.fromJson(CSV2JSON(res.data));
                angular.forEach(data, function (obj, prop) {
                    obj.Link = DataService.buildLink(obj.Link);
                });
                console.log(data);
                scope.data = data;
                return data;
                var anchor = angular.element('<a/>');
                /*anchor.attr({
                    href: 'data:attachment/csv;chartset=utf-8,' + encodeURI(res.data),
                    target: "_blank",
                    download: 'events.csv'
                })[0].click();*/
            });


        };

与以下HTML相关联:

<span ng-csv="exportWidget()" csv-header="['Date', 'Data Source', 'CCMD', 'Country', 'Province', 'IED Type', 'Incident Type', 'Title', 'Link' ]" filename="events.csv" ng-show="item.settings.widgetType ==='table'" class="widget-controls" title="Export"><i class="fa icon-export-file"></i></span>

但是当我点击处理导出的按钮时,我的CSV文件如下所示:

enter image description here

我不确定如何制作它,以便CSV文件实际填充正确的数据。

scope.data数组的样子是this(对象数组): enter image description here

0 个答案:

没有答案