2
我試圖構建一個類來自動化jQuery UI滑塊的實例化。 我已經可以實例化滑塊,讓它們運行等等。 但是,當我綁定滑動事件時,遇到了this
現在是事件的問題。 我已經制作了一個var _self = this;
來解決這個問題,但是會被類的每個實例覆蓋。jQuery UI事件範圍問題
類:
$(function(window){
function WoningSelector(slider_id, min_id, max_id, step, min, max){
this.initialize(slider_id, min_id, max_id, step, min, max);
}
WoningSelector.prototype = {};
var _self;
// Constructor
WoningSelector.prototype.initialize = function(slider_id, min_id, max_id, step, min, max){
this.slider = $('#' + slider_id);
this.min = $('#' + min_id);
this.max = $('#' + max_id);
this.iMin = min;
this.iMax = max;
this.step = step;
_self = this;
_self.slider.slider({
range: true,
step: this.step,
min: this.iMin,
max: this.iMax,
values: [(this.iMin + (this.step * 4)), (this.iMax - (this.step * 4))],
slide: this.slide
});
_self.min.text(this.iMin + (this.step * 4));
_self.max.text(this.iMax - (this.step * 4));
};
// Slide event handler
WoningSelector.prototype.slide = function(event, ui){
_self.min.text(ui.values[0]);
_self.max.text(ui.values[1]);
};
window.WoningSelector = WoningSelector;
}(window));
'slide:this.slide.bind(this)'? –