简体   繁体   English

jQueryUI 小部件问题,如何在 a.defered then() function 中访问选项 hash?

[英]jQueryUI widget question, how can I access options hash within a .deffered then() function?

I am using the widget factory from jQueryUI.我正在使用来自 jQueryUI 的小部件工厂。 I want to access the options hash from within a callback.我想从回调中访问选项 hash。 Inside the callback [_submitMakeHandler], 'this' is a reference to the clicked element.在回调 [_submitMakeHandler] 中,'this' 是对单击元素的引用。

 options: {
    model: {
        vehicleSelections: ko.observable({
            year: ko.observable(),
            make: ko.observable(),
            model: ko.observable(),
            submodel: ko.observable(),
            engine: ko.observable()
        })
    }
},
 _cacheMakes: function () {

    var jqXHR = $.when($.getJSON('VehicleSelection/GetMakes2'));
    jqXHR.then([this._loadMakes, this._templateMakes, this._submitMakeHandler]);
},
 _submitMakeHandler: function (data) {
    $('#formMakeSelection').delegate('a', 'click', function (e) {
        debugger;
        e.preventDefault();
        var container = $(this).closest('div.flyout');
        var link = container.data('el');
        $(link).text(this.text);
       //******* How do I properly access the options from here?????
    });
}

Thanks for any help or tips & tricks.感谢您提供任何帮助或提示和技巧。 I did try this and it works but it seems like the wrong way to be doing it.我确实尝试过这个并且它有效,但它似乎是错误的做法。 $.ui.widgetName.prototype.options

Cheers,干杯,
~ck ~ck

A lot of code here, I will skip to the meat: http://api.jquery.com/jQuery.proxy/这里代码很多,我直接跳肉: http://api.jquery.com/jQuery.proxy/

$.widget('ui.widget',{


  _submitMakeHandler: function( data ){


    $("#formMakeSelection").delegate( 'a', 'click', 
                                      $.proxy( this, '_secretMethod' ) );
  },
  _secretMethod: function( event ){

     event.preventDefault();
     var container = $( event.target ).closest( 'div.flyout' );
     var link = container.data( 'el' );
     //*********** Access this.options
     console.log( this.options );
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM