Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i get widget instance inside a jQuery widget?
    text
    copied!<p>I'm working on a keyboard widget for a project, i'm extending <code>$.ui.mouse</code>. I need click behavior (not triggered by _mouseCapture). I'm having difficulties to get back <code>this.options</code> inside it. See code blocks below :</p> <pre><code>$.widget("ui.keyboard", $.ui.mouse, { widgetEventPrefix: "keyboard", options: { [...] }, [...], _create : function() { this.element.bind('click.'+this.widgetName, this._mouseClick); }, _mouseClick: function(e) { // how do i get this.options here } }); </code></pre> <p>Is it best to do this :</p> <pre><code>$.widget("ui.keyboard", $.ui.mouse, { widgetEventPrefix: "keyboard", options: { [...] }, [...], _create : function() { var self = this; this.element.bind('click.'+this.widgetName, function(e) { self._mouseClick(e, self); }); }, _mouseClick: function(e, self) { // how do i get this.options here -&gt; self.options } }); </code></pre> <p>Or this :</p> <pre><code>$.widget("ui.keyboard", $.ui.mouse, { widgetEventPrefix: "keyboard", options: { [...] }, [...], _create : function() { this.element.bind('click.'+this.widgetName, this._mouseClick); }, _mouseClick: function(e) { var self = $.data(this, "keyboard"); // how do i get this.options here -&gt; self.options } }); </code></pre> <p>I had trouble with the last one when i try to trigger it manually $.data is not up unless i trigger a click on <code>this.element</code> (which is quite logic).</p> <p>Is there some other ways ? Which one is the best to pick ?</p> <p>Thanks,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload