HandsOnTable - 从 0.11.0 升级到 0.15.0-beta 2 后销毁并重新创建不起作用

HandsOnTable - destroy and re-create not working after upgrading from 0.11.0 to 0.15.0-beta 2

我有如下代码:

HTML

<div id="rangePricesGrid" class="handsontable" style="width: auto; overflow: auto"></div>

Javascript:

              var rangePriceGrid = $('#rangePricesGrid').handsontable('getInstance');
                if (rangePriceGrid != undefined) {
                    rangePriceGrid.destroy();
                    if (setRangeGridOptions != undefined)
                        rangePriceGrid = $('#rangePricesGrid').handsontable(setRangeGridOptions);


                } else {
                    if (setRangeGridOptions != undefined)
                        rangePriceGrid = $('#rangePricesGrid').handsontable(setRangeGridOptions);
                }

在页面加载时,它工作正常并绘制了 HOT。但是当我更新 HOT 的一个属性(比如数据,还有列数)然后调用上面的方法时,它在下面失败

rangePriceGrid = $('#rangePricesGrid').handsontable(setRangeGridOptions);

有错误

Uncaught Error: This method cannot be called because this Handsontable instance has been destroyed

我在这里做错了什么?我知道 HOT table 已被销毁,但我正在尝试使用更新的选项重新创建它。

请推荐

我想你明白你正在销毁实例,但你不明白如何重新创建实例。首先,查看 setRangeGridOptions 和 jsfiddle 会很有用。如果您使用 jQuerySelector.handsontable(options) 方法实例化 handsontable,这可能是您出现问题的原因。

您是否考虑过手动删除对先前 HOT 实例的引用,这样您就不会遇到这个问题?尝试以这种方式实例化 HOT:

var hot = new Handsontable($('#rangePricesGrid')[0], setRangeGridOptions)

这样,您应该能够销毁 hot 实例并且您的代码应该开始工作。要销毁热实例,您只需执行以下操作:

hot.destroy()

要重新创建它,请重复使用上面的行。

你可以这样做。

// incorrect

var rangePriceGrid = $('#rangePricesGrid').handsontable('getInstance');

rangePriceGrid.destroy();


// correct

$('#rangePricesGrid').destroy();