jQuery UIの範囲スライダに基づいて電卓を作成しており、その設定が機能しています。私はslide
イベントにスライダーをバインドする私のアプリケーションでbindEvents機能を持っています。ここでは、その後jQuery UIの範囲スライダがpubsubイベントに応答しないのはなぜですか?
// this is where I bind all slide events
bindEvents: function() {
// hold on to the value of this
var self = CloudCalc;
// bind the slider's slide event to a data event
self.sl.on('slide', this.setSliderOutputValue);
}
とは忠実に私のイベントを実行ハンドラです:
setSliderOutputValue: function (event, ui) {
// hold on to the value of this
var self = CloudCalc;
// show the ui output value on slide event
self.output.html(ui.value + " INSTANCE");
}
は今、私は複数のイベントをトリガーしますユーザがスライダをスライドさせると、だから私は、そう(addyosmaniののpubsubプラグインを使用して)のように、このセットアップでオブザーバーパターンを使用したいと思います:
bindEvents: function() {
// hold on to the value of this
var self = CloudCalc;
// bind the slider's slide event and publish it
self.sl.on('slide', $.publish('slider/moved'));
}
ここにサブスクリプションです:
subscriptions: function() {
$.subscribe('slider/moved', this.setSliderOutputValue);
}
このサブスクリプションは、setSliderOutputValue
イベントを呼び出したときに、私を得ますコンソール・エラー・ことわざ:
Uncaught TypeError: Cannot read property 'value' of undefined
UIプロパティへの参照を意味setSliderOutputValue
イベントに渡され取得されていません。
uiプロパティを渡すにはどうすればよいですか?私がこれを間違っていると私を修正してください。