如何子类化特定的jqueryui小部件方法? [英] How to subclass a specific jqueryui widget method?

查看:96
本文介绍了如何子类化特定的jqueryui小部件方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我将jQueryUI更新为1.8,我在实现中发现了一些问题,如果我能找到如何子类化datepicker小部件的特定方法,我就可以自己修复它而无需等待修复它们。父代码,然后执行我的代码。

Since I updated jQueryUI to 1.8 I found a couple of issues in our implementations and I could fix it myself without waiting for a fix on their end if I could find out how to subclass a specific method of the datepicker widget so I call the parent code and then execute my code.

我正在阅读$ .widget,但我无法理解这是如何工作的。

I was reading on $.widget but I just can't wrap my head around how that is suppose to work.

我尝试过这样的事情:

$.widget("ui.datepicker", {
  _showDatepicker: function(input) {
   alert('Yo');
   $.datepicker.prototype._showDatepicker.apply(this,arguments);
   alert('Hey!');
  }
 });

还有各种各样的变化和想法我认为我只是不明白'可扩展性' jQueryUI或它只是无法完成。

And all sorts of other variations and beging to think I just don't understand the 'extendability' of jQueryUI or it just can't be done.

有谁知道我怎么做到这一点?

Anybody knows how I can achieve this ?

Thx

推荐答案

1.8中的datepicker不使用小部件工厂。其他小部件可以,但是日期选择器还没有被重构来使用小部件工厂,这将在更高版本的jQuery UI中发生。

The datepicker in 1.8 doesn't use the widget factory. The other widgets do but the datepicker hasn't been refactored to use the widget factory yet, something that will happen for a later version of jQuery UI.

你可以做点什么比如datepicker:

You can do something like for the datepicker:

var old_showDatepicker = $.datepicker._showDatepicker;
$.datepicker._showDatepicker = function(input){
    console.log('hello');
    old_showDatepicker.apply(this,arguments);
    console.log('goodbye');
}

这是滑块:

$.widget("my.slider", $.ui.slider, {
    _value: function(input) {
        console.log('Yo');
        $.ui.slider.prototype.value.apply(this,arguments);
        console.log('Hey!');
    }
});

这篇关于如何子类化特定的jqueryui小部件方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆