我正在使用jQueryUI中的widget工厂。我想从回调中访问选项哈希。在回调[_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?????
});
}
感谢您提供任何帮助或提示&招数。我确实试过这个并且它有效,但这似乎是错误的做法。$.ui.widgetName.prototype.options
干杯,
〜CK
答案 0 :(得分:0)
这里有很多代码,我会跳到肉: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 );
}
});