
Untitled
By: a guest on
Jul 18th, 2012 | syntax:
None | size: 1.53 KB | hits: 8 | expires: Never
How to access 'this' inside my custom JQuery Widget callback
(function ($, undefined) {
$.widget('custom.MyCarousel', {
options: {
noOfVisibleItems: 2
},
_init: function () { this.BindCarosuel(); },
BindCarosuel: function () {
jQuery(this.element).jcarousel({
size: this.options.noOfVisibleItems.length,
itemLoadCallback: { this.mycarousel_itemLoadCallback }
});
},
MyWidgetCustomMethod: function (index) {
},
mycarousel_itemLoadCallback: function (carousel, state) {
// How to get access to options object (noOfVisibleItems)
// and methods like MyWidgetCustomMethod ?
}
}
)
} (jQuery));
$(this)[0]
or
this[0]
(function ($, undefined)
{
$.widget('custom.MyCarousel',
{
me: this,
options: {
noOfVisibleItems: 2
},
_init: function () { this.BindCarosuel(); },
BindCarosuel: function ()
{
jQuery(this.element).jcarousel({
size: this.options.noOfVisibleItems.length,
itemLoadCallback: { this.mycarousel_itemLoadCallback }
});
},
MyWidgetCustomMethod: function (index) {
},
mycarousel_itemLoadCallback: function (carousel, state) {
// How to get access to options object (noOfVisibleItems)
// and methods like MyWidgetCustomMethod ?
alert(me.options.noOfVisibileItems);
}
})
}(jQuery));
itemLoadCallback: { $.proxy(Self.mycarousel_itemLoadCallback, this) }