开发者

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

开发者 https://www.devze.com 2023-03-21 04:10 出处:网络
I am using the widget factory from jQueryUI.I want to access the options hash from within a callback.Inside the callback [_submitMakeHandler], \'this\' is a reference to the clicked element.

I am using the widget factory from jQueryUI. I want to access the options hash from within a callback. Inside the callback [_submitMakeHandler], 'this' is a reference to the clicked element.

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

    var 开发者_Python百科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


A lot of code here, I will skip to the meat: 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 );
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消