且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未捕获的类型错误:无法读取未定义的属性“datatable”。

更新时间:2022-10-28 11:16:13

在将if语句放入之前,您收到错误,因此无法解决问题。 google.visualization未加载,因此您收到错误,因为未定义可视化时无法读取DataTable。



您可以使用try catch来检查它

When I turn off Google API I get an "Uncaught TypeError: Cannot read property 'DataTable' of undefined" message.

I would like to catch this undefined error and have a window popping up saying "Google has been disabled" but I'm not sure what typeof is undefined. I'm currently checking "DataTable" type but the window pops up regardless now.

Can someone help me please?

What I have tried:

Here is my code.


var data = new google.visualization.DataTable();
if(typeof DataTable == "undefined"){
window.alert("sometext");
} else {
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
data.addColumn('string', 'Type');
data.addColumn('string', 'Code');
data.addColumn('string', 'Aggregation');
data.addColumn('string', 'Stage');

data.addRows([
<xsl:apply-templates select="/*" mode="render"/>
['1','2','3','4','5','6','7']
]);

data.removeRow(data.getNumberOfRows() - 1);

drawDebugFlow(data);
}

You are getting the error before you put the if statement in so it won't help there. google.visualization is not loaded so therefore you get the error that DataTable cannot be read on undefined because visualization is undefined.

You can use a try catch to check for it.