Я определил базу своего плагина на http://docs.jquery.com/Plugins/Authoring
(function( $ ){
var methods = {
init : function( options ) { },
show : function( options ) { },
hide : function( ) { },
update : function( content ) {
// How to call the show method inside the update method
// I tried these but it does not work
// Error: not a function
this.show();
var arguments = { param: param };
var method = 'show';
// Error: options is undefined
methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
}
};
$.fn.tooltip = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
Как вызвать метод show внутри метода обновления?
EDIT :
show
ссылка на метод this
.Использование methods.show(options)
или methods['show'](Array.prototype.slice.call( arguments, 1 ));
работает для вызова метода show
, но тогда ссылка на this
кажется неправильной, потому что я получил ошибку this.find(...) is not a function
.
Метод show
:
show: function(options) {
alert("Options: " + options);
alert("Options Type: " + options.interactionType);
var typeCapitalized = capitalize(options.interactionType);
var errorList = this.find('#report' + typeCapitalized);
errorList.html('');
},