Javascript Handsontable - Uncaught TypeError: Cannot read property 'insertBefore' of undefined

爱⌒轻易说出口 提交于 2019-12-23 04:09:15

问题


I'm using the handsontable library for creating neat tables.
I literally copied the tutorial but the console (web developer console) gives me the following error:

Uncaught TypeError: Cannot read property 'insertBefore' of undefined            
handsontable.full.js:4471 

I link both the .css and the .js file correctly in the <head> tags.

My javascript looks like this:

var data = [
    ["", "Ford", "Volvo", "Toyota", "Honda"],
    ["2016", 10, 11, 12, 13],
    ["2017", 20, 11, 14, 13],
    ["2018", 30, 15, 12, 13]
];

var container = document.getElementById('temp');
var hot = new Handsontable(container, {
    data: data,
    rowHeaders: true,
    colHeaders: true,
    dropdownMenu: true
});

Html:

<div id="temp"></div>

Line 4471 in handsontable.full.js is

rootElement.insertBefore(this.container, rootElement.firstChild);

The table isn't displayed, the error in the console is all I've got.


回答1:


It looks like that your

document.getElementById('temp');

return undefined.

Make sure that the container element is still there when Handsontable is constructing.




回答2:


Your rootElement reference is undefined. Please check where is this variable defined and to what it is assigned.



来源:https://stackoverflow.com/questions/36624007/javascript-handsontable-uncaught-typeerror-cannot-read-property-insertbefore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!