有没有办法从元素获取 SlickGrid 的实例
刚开始使用 SlickGrid ,它似乎不像普通的 jquery 小部件/插件那样自行启动只需执行 $(element).slickgrid() 即可访问附加到元素的实例。
有没有一种方法可以获取现有实例,而无需在创建实例时明显保留它?查看代码似乎并非如此,但不确定其他人是否遇到过这种情况。
不太清楚为什么他们依赖 jquery 但决定进行自定义初始化。
可以像将其包装在 jqueryui 小部件中一样简单。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以使用 jQuery 的数据函数来保存对光滑网格实例的引用。
例如:
您可以使用以下方式访问它:
You could always use jQuery's data function to save a reference to the slick grid instance.
For example:
And you can access it using:
我觉得这类问题有点好笑。仅仅因为某些东西使用了 jQuery 库,它并不会自动使其成为 jQuery 插件或 jQueryUI 小部件。 SlickGrid 两者都不是,这就是为什么它不遵循他们的设计约定或 API。
撇开那些小抱怨不谈,马克的回答是正确的。如果由于某种原因你想用 DOM 元素存储实例变量,你可以使用 $(element).data() 轻松实现。
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().