vendredi 28 novembre 2014

Uncaught TypeError: object is not a function after second refresh


At the moment I'm facing a javascript problem. This is the javascript code:



$(document).ready(function() {
/*
createNewTodo("_OPDRACHT_", "_PRIO_", "_DONE_");

_OPDRACHT_ = wat er gedaan met worden.
_PRIO_ = prioriteit 1-5 (1 is hoogste, 5 is laagste)
_DONE_ = uitgevoerd 1-2 (1 is nee, 2 is ja
*/

function todo(opdracht,prio,done) {
this.opdracht = opdracht;
this.prio = prio;
this.done = done;
}

function createNewTodo(opdracht,prio,done) {
var createdTodo = new todo(opdracht,prio,done);
if ( localStorage.todoCount == undefined ) {
localStorage.setItem('todoCount', 0)
}
var todoSize = parseInt(localStorage.todoCount) + 1;
commitToStorage(todoSize,createdTodo);
}

function addList(){
var val = $('#name').val();
var tjap = createNewTodo(val,"1","1");
}

function commitToStorage(objectCount,newObject) {

var item = + objectCount;
localStorage.setItem('todoCount', objectCount);

localStorage.setItem(item, JSON.stringify(newObject));
}

var todoCount = localStorage.getItem('todoCount');
for (i=1;i<=todoCount;i++)
{
var number = parseInt(i) + 1;
var todo = jQuery.parseJSON(localStorage.getItem(+ i));
createMarkup(todo);
}

function createMarkup(todo) {
$('ul#items').append(
"<li>" +
todo.opdracht + " " +
"</li>"
);
}

$('#add-btn').click(addList);

});


When I click on the add-btn it will insert a item in localstorage with a array of values. Everything is working fine until I refresh the page. At the first time I can add as many items in localstorage without a problem but when I try to add items after refreshing the page I get the following error: Uncaught TypeError: object is not a function. Been searching a lot on the internet but could't find a appropriate solution for this. Anyone that can help me out and push me in the right direction? Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire