HTML and CSS Reference
In-Depth Information
Next, remember to include the import in the page at the end of the head section of
tasks.htmk, and also remember to add a reference to the file in tasks.appcache, since we
want this library to be available offline.
<script src="scripts/jquery.csv-0.71.js"></script>
You can check you have installed the script correctly by executing the following call in the
console and checking an object is returned:
$.csv
We can now write code to parse and create tasks:
function loadTask(csvTask) {
var tokens = $.csv.toArray(csvTask);
if (tokens.length == 3) {
var task = {};
task.task = tokens[0];
task.requiredBy = tokens[1];
task.category = tokens[2];
return task;
}
return null;
}
function loadFromCSV(event) {
var reader = new FileReader();
reader.onload = function(evt) {
var contents = evt.target.result;
var lines = contents.split('\n');
var tasks = [];
$.each(lines, function(indx, val) {
if (indx >= 1 && val) {
var task = loadTask(val);
if (task) {
tasks.push(task);
}
}
Search WWH ::




Custom Search