Is there a way to get an instance of SlickGrid from an element

橙三吉。 提交于 2019-12-10 14:59:22

问题


Just starting to use SlickGrid and it doesn't seem to initiate itself like a normal jquery widget/plugin does where you can access the instance attached to the element by just doing $(element).slickgrid() .

Is there a way to get a hold of the existing instance, without obviously holding onto it when you create it? Looking through the code it didn't seem like it, but wasn't sure if anybody else had run into this.

Not exactly sure why they took dependencies on jquery but decided to have a custom initialization.

Could be as simple as just wrapping it in a jqueryui widget.


回答1:


You could always use jQuery's data function to save a reference to the slick grid instance.

For example:

var grid = new Slick.Grid(container,data,columns,options);
$(element).data('slickgrid', grid);

And you can access it using:

$(element).data('slickgrid');



回答2:


I find these kinds of questions kinda funny. Just because something uses the jQuery library, it doesn't automatically make it a jQuery plugin or a jQueryUI widget. SlickGrid is neither, which is why it doesn't follow their design conventions or APIs.

That minor rant aside, Mark's answer is correct. If for some reason you want to store the instance variable with the DOM element, you can easily do that with $(element).data().



来源:https://stackoverflow.com/questions/5573806/is-there-a-way-to-get-an-instance-of-slickgrid-from-an-element

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