Uncaught TypeError: Cannot read property '...' of null(…)
Uncaught TypeError: Cannot read property '...' of null(…)
My datatables have worked for a very long time without any problems, but today I revisited my page to find that suddenly it doesn't properly read the JSON data anymore.
This is my page: http://jtc.ae/?page=s_page
You need to do launch_datatable();
in console to launch it.
Basically I create my tables with JSON data and configured them like this: "data":jsonData,
Then I format my columns like this:
"columns": [
{ "data" : "post_title" },
{ "data" : "post_meta.price_input",
"defaultContent" : "",
"render" : function( data, type, full, meta ){
//Get the USD rate
var dol_rate = $("#dol_rate").val();
var curr = full.post_meta.price_input_currency;
This is where the bug occurs, it cannot recognise this full.post_meta.price_input_currency;
anymore...
Any ideas?
This question has an accepted answers - jump to answer
Answers
Since it didn't happen on page 2 apparently it has to do with json data that was loaded which had
null
as value insidefull.post_meta
.I had to delete those objects as the whole page was bugging because of that but, any way to prevent this from happening in the future?
Hi,
Since your code is trying to access a property of the
full.post_meta
object you would need to first check if it isnull
or not. That is in yourcolumns.render
code, so it isn't something that DataTables will do for you (it can't!).Allan
Something like
if(full.post_meta!=null){ ... }
?Looks fine to me.