简体   繁体   English

如何使用ExtJS客户端上传和处理CSV文件

[英]How to upload and process CSV File using ExtJS Client Side

I am trying to Upload a CSV File containing IP addresses using Ext-js and have it processed and converted into a JSON Object on the client-side before sending it to the server to be added to the repository. 我正在尝试使用Ext-js上传包含IP地址的CSV文件,并在将其发送到服务器以添加到存储库之前对其进行处理并转换为客户端的JSON对象。 I need to parse the CSV, convert it into a JSON Object and then add the information to a Data Store- but I'm terribly stuck. 我需要解析CSV,将其转换为JSON对象,然后将信息添加到数据存储中,但是我非常困扰。 Are there any existing libraries that can help achieve this? 是否有任何现有的库可以帮助实现这一目标? I am looking at avoiding jQuery/HTML5. 我正在考虑避免使用jQuery / HTML5。 Is there a way we can do it exclusively using Javascript / Extjs? 有没有一种方法可以独家使用Javascript / Extjs来做到这一点? I tried going through a lot of examples- but most of them use jQuery/HTML5 API/ Papa-Parse or prefer doing it server side. 我尝试了很多示例,但是大多数示例都使用jQuery / HTML5 API / Papa-Parse或更喜欢在服务器端进行操作。

My 'Upload' Button handler function looks like this: 我的“上传”按钮处理程序函数如下所示:

handler: function () {
      var file = Ext.getCmp('form-file-win').getEl().down('input[type=file]').dom.files[0];

                    var reader = new FileReader();
                    var importedAddresses=[];
                   reader.onload = function (oFREvent) {
                       importedAddresses=oFREvent.target.result;
                    };
                  reader.readAsText(file);
                    this.dataStore.add({
                       id: '',
                       name: 'Imported from CSV',
                   });
                    win.close();
                }

Unfortunately there is no way to access the content of the file on the client side. 不幸的是,无法在客户端访问文件的内容。 You have two options: 您有两种选择:

  1. You either post the file to the server and process it serves-side and give a json response for your javascript 您可以将文件发布到服务器并处理它的服务端,并为您的JavaScript提供json响应
  2. Or you need to use HTML5 to access a local file. 或者,您需要使用HTML5访问本地文件。 Here is a tutorial on how to do that: local file processing 这是有关如何执行此操作的教程: 本地文件处理

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

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