Tuesday, 10 September 2013

Uncaught TypeError: in javascript

Uncaught TypeError: in javascript

I have a url and I fetch the data from backend in backbone.js
defaults : {
id : null,
name : null,
timestamp : null
},
url : "/path/user",
parse : function(response){
if(response.id === undefined){
response.id = response.id;
}
else console.dir(response.id);
response.name = response.name;
if(response.timestamp.$date === undefined){
response.timestamp = response.timestamp.$date;
}
else console.dir(response.timestamp.$date);
return response;
},
Since not all the json object do not have ID this is the error that I get:
Uncaught TypeError: Cannot read property 'oid' of undefined I tried to
catch the error by adding if undefined in the above code, but I stll have
the error, how can I avoid the error?

No comments:

Post a Comment