2011-01-17 7 views
0

私はjquery ui plugin for dialogsと同様の使い方をしているプラ​​グインを作成しようとしています。私の後の使用法はこのようになりますjquery uiのようなパラメータ受け入れのjqueryプラグインの作成

まず、(デフォルトのアクションで)プラグインのオプションを設定するために、このようなパラメータを渡すことができます。

$('#myId').dialog({ 
    value1 : 'someValue', 
    value2 : 'anotherValue', 
    //... 
}); 

また、「キーワード」を使用して特定のイベントを配線したいと考えています。 jquery.UI内のインスタンスのためには、ダイアログ

$('#myId').dialog('close'); 

私の質問は、それが設定に渡されているか、それが依存する他の事をした場合、それは一つのことを行うように私のセットアップ私のプラグインを行う方法です閉じるために、これを呼び出すことができます渡されたキーワードについて私はjQuery UIのコードのいくつかを見てみましたが、私はそれが何をしているのか、あるいはどこからこの機能を引き出すのかを理解していません。あなたが渡されているオブジェクトの種類

答えて

3

を使用する場合がありますが、具体的Plugin MethodsjQuery Plugins/Authoringを見て、持っています。

例:次に

(function($){ 

    var methods = { 
    init : function(options) { /* THIS */ }, 
    show : function() { /* IS */ }, 
    hide : function() { /* GOOD */ }, 
    update : function(content) { /* !!! */ } 
    }; 

    $.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); 

...

0

チェック:

if (typeof arguments[0] === 'string') { 
// I was given a string, my convention tells me this is a command 
} else if (typeof arguments[0] === 'object') { 
    // my convention tells me that this is an instantiation object 
} 

あなたはまた、オブジェクトのプロパティを確認したい、または$.isArray()

関連する問題