我想在遺留 GWT 應(yīng)用程序中使用 Tabulator。我正在從本機(jī) JS(GWT 的 ScriptInjector 中包含的文件)創(chuàng)建 Tabulator。這是我的代碼: const table = new Tabulator($(".tabulatordiv_id")[0], { data:tabledata, //assign data to table layout:"fitColumns", //fit columns to width of table (optional) columns: [{title:"Name", field:"name"}] });我收到錯(cuò)誤:“制表符創(chuàng)建錯(cuò)誤 - 提供的元素?zé)o效”。我查看了 Tabulator 并發(fā)現(xiàn)它停在這里:Tabulator.prototype.initializeElement = function (element) { if (typeof HTMLElement !== "undefined" && element instanceof HTMLElement) { this.element = element; return true; } else if (typeof element === "string") { this.element = document.querySelector(element); if (this.element) { return true; } else { console.error("Tabulator Creation Error - no element found matching selector: ", element); return false; } } else { console.error("Tabulator Creation Error - Invalid element provided:", element); return false; }};因?yàn)椤霸?instanceof HTMLElement”是 FALSE。我從遺留應(yīng)用程序中拉出頁面并使其工作盡可能與原始應(yīng)用程序相似(拉入相同的 js 庫,拉入 GWT js 文件等)以重現(xiàn)問題,但失敗了。我無法在舊版應(yīng)用程序之外復(fù)制它。但是,如果我將 Tabulator.js 中的 init 更改為更寬松一點(diǎn),如下所示:// if (typeof HTMLElement !== "undefined" && element instanceof HTMLElement) { if (typeof HTMLElement !== "undefined" && typeof element !== "string") { this.element = element;然后就可以了。我很確定我傳遞給 Tabulator 的是一個(gè) HTMLElement(在瀏覽器中雙重檢查,具有 HTMLElement 應(yīng)具有的所有屬性)。所以我想問一下“instanceof HTMLElement”檢查的基數(shù)是多少?如果我繞過 Tabulator init 中的檢查,以后遇到麻煩的可能性有多大?
Tabulator init 中的元素 instanceof HTMLDivelement
動(dòng)漫人物
2023-03-03 15:27:05