책과 인터넷으로 공부를 하고 있긴한데 이쪽 전공이 아니다보니 막히는 부분이 많네요.
최종 목표는 phonegap에서 사용하려 하는데요. 항상 질문만 드리게 되어 죄송합니다.
html5에서 csv파일 출력할때 테이블 형식으로 출력이 되던데 특정 열만 select tag에 나오도록 할 수 있나요?
아래는 코드인데요.혹시 어느 부분을 고쳐야 하는지 아시는분 계시면 부탁드릴께요.
function handleFiles(files) {
// Check for the various File API support.
if (window.FileReader)
{
// FileReader are supported.
getAsText(files[0]);
}
else
{
alert('FileReader are not supported in this browser.');
}
}
function getAsText(fileToRead)
{
var reader = new FileReader();
// Handle errors load
reader.onload = loadHandler;
reader.onerror = errorHandler;
// Read file into memory as UTF-8
reader.readAsText(fileToRead);
}
function loadHandler(event)
{
var csv = event.target.result;
processData(csv);
}
function processData(csv)
{
var allTextLines = csv.split(/\r\n|\n/);
var lines = [];
while (allTextLines.length)
{
lines.push(allTextLines.shift().split(','));
}
console.log(lines);
drawOutput(lines);
}
function errorHandler(evt)
{
if(evt.target.error.name == "NotReadableError")
{
alert("Canno't read file !");
}
}
function drawOutput(lines)
{
//Clear previous data
document.getElementById("output").innerHTML = "";
document.getElementById("list").innerHTML = "";
var table = document.createElement("table");
for (var i = 0; i < lines.length; i++)
{
var row = table.insertRow(-1);
for (var j = 0; j < lines[i].length; j++)
{
var firstNameCell = row.insertCell(-1);
firstNameCell.appendChild(document.createTextNode(lines[i][j]));
}
}
document.getElementById("output").appendChild(table);
}