我想在遺留 GWT 應用程序中使用 Tabulator。我正在從本機 JS(GWT 的 ScriptInjector 中包含的文件)創建 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"}] });我收到錯誤:“制表符創建錯誤 - 提供的元素無效”。我查看了 Tabulator 并發現它停在這里: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; }};因為“元素 instanceof HTMLElement”是 FALSE。我從遺留應用程序中拉出頁面并使其工作盡可能與原始應用程序相似(拉入相同的 js 庫,拉入 GWT js 文件等)以重現問題,但失敗了。我無法在舊版應用程序之外復制它。但是,如果我將 Tabulator.js 中的 init 更改為更寬松一點,如下所示:// if (typeof HTMLElement !== "undefined" && element instanceof HTMLElement) { if (typeof HTMLElement !== "undefined" && typeof element !== "string") { this.element = element;然后就可以了。我很確定我傳遞給 Tabulator 的是一個 HTMLElement(在瀏覽器中雙重檢查,具有 HTMLElement 應具有的所有屬性)。所以我想問一下“instanceof HTMLElement”檢查的基數是多少?如果我繞過 Tabulator init 中的檢查,以后遇到麻煩的可能性有多大?
Tabulator init 中的元素 instanceof HTMLDivelement
動漫人物
2023-03-03 15:27:05