简体   繁体   English

显示CSV / JSON文件中的特定数据

[英]Displaying specific data from a CSV/JSON file

I want to display specific fields from an external CSV file on a web site with using JavaScript. 我想使用JavaScript在网站上显示来自外部CSV文件的特定字段。 I tried to parse that file with using "Papa parse" like this: 我试图使用“ Papa parse”来解析该文件,如下所示:

 <!DOCTYPE html> <html > <head> <meta charset="UTF-8"> <title>Parse remote CSV to HTML Page</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <script src='http://d3js.org/d3.v3.min.js'></script> <script src='https://code.jquery.com/jquery-2.1.4.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.2/papaparse.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.0/mustache.min.js'></script> <script> Papa.parse("https://dl.dropboxusercontent.com/s/....../data.csv?dl=0", { download: true, header: true, complete: function(results) { console.log(results); } }); </script> </body> </html> 

And this give me the result in console: 这给了我控制台的结果:

console.log 的console.log

My question is; 我的问题是; How can I display a specific data from this data set in a web site like: 如何在网站中显示来自此数据集的特定数据,例如:

Battery Level: 0.62 电池电量: 0.62

Altimeter Pressure: 99.44185 高度计压力: 99.44185

Horizontal Accuracy: 65 水平精度: 65

etc. etc. 等等等

Taking Battery Level as an example (the other fields are similar and you should be able to figure it out youself): 以电池电量为例(其他字段相似,您应该可以自己弄清楚):

var data = results.data
var arrayLength = data.length;
for (var i = 0; i < arrayLength; i++) {
    var newdiv = document.createElement('div');

    newdiv.setAttribute('id', 'your_div_id_'+i.toString());

    newdiv.innerHTML = 'Battery Level: '+data[i].batteryLevel.toString();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM