HTML and CSS Reference
In-Depth Information
Finally, lets add the call to saveAll in our code:
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);
}
}
});
storageEngine.saveAll('task', tasks, function() {
tasksController.loadTasks();
},errorLogger);
};
reader.onerror = function(evt) {
errorLogger('cannot_read_file', 'The file specified cannot be read');
};
reader.readAsText(event.target.files[0]);
}
With this in place, you should be able to load a CSV file and have the contents immediately
reflected in the tasks table. In addition; it is also possible to use this functionality without
connectivity to a web server, since all the processing is occurring entirely on the client.
Search WWH ::




Custom Search