SteveP
SteveP

Reputation: 19103

jqueryui widget factory change method

I am writing a jqueryui widget, and I want to get at some widget data when the widget changes (using _trigger). I am using the widget as follows:

$("#myDiv").myWidget({
    change: function(e) {
        alert($("#filter").myWidget('getWidgetData'));
        // do something with the widget data.
    }
});

This code works (the alert fires and show the widget data when the widget calls _trigger). However, is this the correct/best way to get at the widget data inside the change callback ? For isntance, I can't seem to call this.getWidgetData, or e.getWidgetData.

Upvotes: 0

Views: 108

Answers (1)

rd3n
rd3n

Reputation: 4560

You can attached your data to the change event you triggered. You should have something like :

this._trigger('change', e);

and could use :

this._trigger('change', e, { widgetData: this.getWidgetData() });

The _trigger function accepts A hash of data associated with the event. as its third arg as decribed in the documentation.

And your code will become :

$("#myDiv").myWidget({
    change: function(e, data) {
        alert(data.widgetData);
        // do something with the widget data.
    }
});

Upvotes: 1

Related Questions