[英]How to catch Uncaught typeerror: cannot read property 'datatable' of undefined. error
當我關閉Google API時,收到“未捕獲的TypeError:無法讀取未定義的屬性'DataTable'”消息。
我想捕獲此未定義的錯誤,並彈出一個窗口,說“ Google已被禁用”,但是我不確定未定義哪種typeof對象。 我目前正在檢查“ DataTable”對象,但是我很確定這是錯誤的,因為無論現在如何都會彈出窗口。
這是我的代碼。
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);
}
代替:
if(typeof DataTable == "undefined"){
采用:
if(typeof google == "undefined" || typeof google.visualization == "undefined"){
錯誤是“未捕獲的TypeError:無法讀取未定義的屬性'DataTable'”而不是“ Datatable未定義”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.