2011-07-15 8 views
0

: jQueryの1.3.2 jqueryのUI 1.7.2jqueryのウィジェットのヘルプ

は、私は次のjQueryスニペットを見つけたが、それとの問題を抱えています。

$(document).ready(function() { 
     $.widget("ui.hello", { 
      options: { 
       foo: "bar", 
       baz: "quux" 
      }, 
      _init: function() { 
       var text = this.options.text; 
       this.element.innerHTML("hello " + this.options.foo + " and " + this.options.baz); 
      } 
     }); 

     $("#thing").hello({ foo: "WORLD!" }); 
    }); 

ここで問題です:

this.options.baz)。 は定義されていませんデフォルトを使用しないでください。

ソース: http://blog.citrusbyte.com/2010/09/16/jquery-widgets-bringing-sanity/

答えて

0

は、ここに私がやってしまったものです:

<script type="text/javascript">  
     $(document).ready(function() { 
      $.widget("ui.hello", { 

       _init: function() { 
        var text = this.options.text; 
        alert(this.options.baz); 
       } 
      }); 

      $.extend($.ui.hello, { 
       defaults: { 
        baz: "whatever" 
       } 
      }); 
      $("#thing").hello({ foo: "WORLD!" });    
     });   
    </script> 
0

thisおそらく_init関数が呼び出されたときにコンテキストを呼び出すことにより、ウィジェットを参照していません。 this.を削除してみて、ちょうどそのようなオプションを参照してください。

this.element.innerHTML("hello " + options.foo + " and " + options.baz); 
関連する問題