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

查看:241
本文介绍了HandsOnTable - 从0.11.0升级到0.15.0-beta 2后,销毁并重新创建不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

HTML

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

Javascript:

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的其中一个属性(比如数据和列数)然后调用上面的方法时,它会在下面失败

On page load, it works fine and paints the HOT. But then when I update one of the properties (say Data, and number of columns also) of HOT and then calls above method, it fails at the below

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

有错误

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

什么我在这里做错了吗?我知道HOT桌子已被破坏,但我试图用更新的选项重新创建它。

What am I doing wrong here ? I know the HOT table is destoryed, but I am trying to re-created it with updated options.

请建议

推荐答案

我认为您了解到您正在销毁实例,但您不了解如何重新创建实例。要开始它是有用的看到 setRangeGridOptions ,也许也是一个jsfiddle。如果您使用jQuerySelector.handsontable(options)方法实例化handontable,则可能是您遇到问题的原因。

I think you understand that you're destroying the instance but you don't understand how to recreate the instance. To start it would be useful to see setRangeGridOptions and maybe also a jsfiddle. If you're instantiating handsontable using the jQuerySelector.handsontable(options) method, it may be the cause of your problems.

您是否考虑过手动删除之前的引用HOT实例让你没有这个问题?尝试以这种方式实例化HOT:

Have you considered manually erasing the reference to the previous HOT instance so you don't have this problem? Try instantiating HOT this way:

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

这样,你应该可以销毁 hot 实例,你的代码应该开始工作了。要销毁热实例,你只需要做:

This way, you should be able to destroy the hot instance and your code should start working. To destroy the hot instance you would simply do:

hot.destroy()

要重新创建它,您可以重复使用上面的行。

And to recreate it, you reuse the line above.

这篇关于HandsOnTable - 从0.11.0升级到0.15.0-beta 2后,销毁并重新创建不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆