将CSV文件读入JavaScript字符串或数组 [英] Reading CSV file into javascript string or array

查看:180
本文介绍了将CSV文件读入JavaScript字符串或数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常具体的问题,所以我希望有人可以帮助。我正在使用CakePHP后端框架构建地图应用程序。我目前正试图导入一些数据到我的应用程序进行操纵,我有一个google docs CSV文件(我也有一个本地版本),我也使用自定义js库。所以我有一个声明如下:

I'm having a very specific problem so I hope someone can help. I'm building a map app with a CakePHP backend framework. I'm currently attempting to import some data into my application for manipulation, I have a google docs CSV file (i also have a local version) and I'm also using an custom js library. So i have a declaration that goes like so:

mapbox.markers.layer()。csv('csvstring');

csvstring等同于CSV数据的标准字符串,我查看了mapbox网站上的一些示例,但都有硬编码数据,例如 csvstring ='lat,lon\\\
,0,0';

csvstring equates to a standard string of CSV data, i looked at some examples on the mapbox website but all had hardcoded data, e.g. csvstring = 'lat,lon\n,0,0';

无论是google doc,还是从我的CakePHP目录中读取文件,变成字符串变量,否则,一个数组?我已经洗了几天的互联网,没有能够找到一个解决方案。如果它可能让PHP做脏工作,然后传递字符串到js var然后那将是伟大的。最后,它必须是字符串或字符串数​​组。

Is there a simple way to read either the google doc, or read the file from my CakePHP directory, into a string variable or, failing that, an array? I've scoured the internet for days and haven't been able to find a solution. If its possible to let PHP do the dirty work and then pass the string to a js var then that would be great also. In the end it must be a string, or an array of strings.

我看到很多人推荐熟悉Google文档API,但是我真的不喜欢CakePHP和JavaScript,并且花了很多时间的工作,以获得这远,我的头是充满爆破点,我只是不认为我会能够进行另一个大的阅读会话,时间正在耗尽我的项目。

I've seen a lot of people recommending getting familiar with the Google Docs API, but really, I'm a nooby with both CakePHP and javascript and its taken a lot of work to get this far, my head is full to bursting point and I just dont think i'll be able for another big reading session, time is running out on my project. Also, dont assume I know ANYTHING, a complete idiots response would be greatly appreciated, thanks in advance.

推荐答案

使用reqwest:

这篇关于将CSV文件读入JavaScript字符串或数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆