【问题标题】:JQuery Widget Factory override _setOptionsJQuery Widget Factory 覆盖 _setOptions
【发布时间】:2013-03-26 20:50:16
【问题描述】:

我正在尝试覆盖 jQuery Widget Factory 的内置 _setOptions 方法,但我不知道如何调用父 _setOptions 函数。我使用的是 jQuery 1.8.24,所以我不能使用仅在 1.9+ 中可用的 super 方法。

      _setOption: function(key, value){
          console.log('key => '+ key + '; value => '+ value); // Test to see if this gets called
          if(this[key] != value) {
              $.Widget.prototype._setOption.apply(this,arguments); // Call the parent option
          }    
      },   

      _setOptions: function(options){
          console.log('Config multi options');
          console.log(options);
          //$.Widget.prototype._setOptions.apply(this, options); // throws error
          // Ripped out the guts of Widget _setOptions for now.  Feels hackish.
          var self = this;
          $.each(options, function(key, value) {
              self._setOption(key, value);
          });
          // What to do after finished setting multiple options.
          this._configureVideo();
          this.play();
      }, 

jquery UI 1.9 WidgetFactory Documentation

【问题讨论】:

  • 我相信在使用 jQuery Widgets 时 _methods 是私有的
  • 您在技术上是正确的。但是,您仍然可以覆盖这些方法,并且它们对于您和您的小部件仍然是 private。如果没有_,它们是前端可以访问的公共方法。

标签: jquery jquery-widgets


【解决方案1】:

你可以使用 this._setOption();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    相关资源
    最近更新 更多