我正在构建一个基于 HTML 的应用程序,用于使用 AlaSQL 查询导入的 CSV 文件。我开始于这个演示 http://alasql.org/demo/008file/并尝试通过设置来实现相同的行为onChange
事件通过 JQuery 而不是在标签中。我基本上遵循相同的模式,并天真地将事件转发给loadFile
方法。或者,我尝试只处理alasql
在回调中请求。
html:
<input id="with-jquery" name="with-jquery" type="file" />
javascript:
$('#with-jquery').on('change', function(event)
{
console.log('in jquery callback');
filename = $('#with-jquery').val();
console.log("filename: " + filename);
alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(res){
console.log('in alasql callback');
data = res;
console.log(res);
document.getElementById("jquery-result").textContent = JSON.stringify(res);
});
//loadFile(event);
});
http://plnkr.co/edit/FOWwVsW7zAUGwv3BDBdN?p=preview http://plnkr.co/edit/FOWwVsW7zAUGwv3BDBdN?p=preview
当我尝试使用 JQuery 处理程序加载文件时,我得到
in jquery callback
test.js:7 filename: C:\fakepath\sample.csv
alasql.min.js:13 Uncaught Error: Wrong usage of FILE() function
这里有一些问题:
- 我找不到 alasql 所期望的文档
[event]
slot.
- 如何
FROM FILE
方法涉及更具体的FROM CSV
and FROM XLSX
方法。
- The wiki https://github.com/agershun/alasql/wiki/Csv显示使用
FROM CSV
方法通过提供文件名。我无法想象如果不提供本地文件的完整路径,这将如何工作。但你无法从浏览器中获取它。
- The wiki https://github.com/agershun/alasql/wiki/promise还建议使用“承诺”格式 https://github.com/agershun/alasql/wiki/promise。我将如何在这里实现它?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)