javascript - Displaying CSV Headers using PapaParse Plugin - Stack Overflow

I am using the PapaParse plugin for csv files. I have this function below that creates a table to displ

I am using the PapaParse plugin for csv files. I have this function below that creates a table to display the CSV results.

function handleFileSelect(evt) {
var file = evt.target.files[0];

Papa.parse(file, {
  header: true,
  dynamicTyping: true,
  plete: function(results) {

    $.each(results.data, function(i, el) {
        var row = $("<tr/>");
        row.append($("<td/>").text(i));
        $.each(el, function(j, cell) {
                row.append($("<td/>").text(cell));
        });
        $("#results tbody").append(row);
    });


  }
  });

}

Even with header:true set, I can not seem to get the headers to show up in the table but the rest displays perfectly.

And to be honest, I found this script online and am having trouble even understanding how it is working.

Any ideas? Thank you in advance!

I am using the PapaParse plugin for csv files. I have this function below that creates a table to display the CSV results.

function handleFileSelect(evt) {
var file = evt.target.files[0];

Papa.parse(file, {
  header: true,
  dynamicTyping: true,
  plete: function(results) {

    $.each(results.data, function(i, el) {
        var row = $("<tr/>");
        row.append($("<td/>").text(i));
        $.each(el, function(j, cell) {
                row.append($("<td/>").text(cell));
        });
        $("#results tbody").append(row);
    });


  }
  });

}

Even with header:true set, I can not seem to get the headers to show up in the table but the rest displays perfectly.

And to be honest, I found this script online and am having trouble even understanding how it is working.

Any ideas? Thank you in advance!

Share Improve this question asked Oct 27, 2014 at 21:50 VIDesignzVIDesignz 4,7833 gold badges30 silver badges38 bronze badges 1
  • 1 Enabling header row support simply keys data on every row by the field name. Without header row, the data is returned as an array of arrays, so you would access values numerically. With header row, though, data is an array of objects, and the first row is consumed as the header row, not as part of the data. – Matt Commented Oct 28, 2014 at 4:30
Add a ment  | 

2 Answers 2

Reset to default 8

Well, I figured it out...

The header titles were contained within a different object. results.meta['fields']

This is how I am printing the results from papa parse.

$.each(results.meta['fields'], function(i) {
    $("#headers").append($("<td/>").text(results.meta['fields'][i]));
});

try using header:false, it'll display the header as array.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743740161a4498991.html

相关推荐

  • javascript - Displaying CSV Headers using PapaParse Plugin - Stack Overflow

    I am using the PapaParse plugin for csv files. I have this function below that creates a table to displ

    7天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信