试图扩展小部件时出现错误,为什么?

问题描述:

这里有两个小部件。试图扩展小部件时出现错误,为什么?

http://pastebin.com/kheULT7h

如果我尝试和延伸远离 'sb.baseApp' sb.textboxesApp“我得到一个错误:

”类型错误:s不是一个构造函数“

但是,为什么? ??

是不是你如何扩展一个小部件?

的jQuery 1.8.3 jQuery UI的1.10.3

我觉得你应该自己通过小部件.widget的第二个参数()。不是一个字符串。这是我的测试。 http://jsfiddle.net/ho873kz4/

/**************************** 

Base Widget 

     Requires jQuery 
     Requires jQuery UI 

****************************/ 

(function($, undefined) { 
     'use_strict'; 



     /* 
     * A widget. 
     */ 
     $.widget('sb.baseApp', { 
       /* 
       * Widget Option 
       */ 
       options: {}, 



       /* 
       * Constructor, called once when first created 
       */ 
       _create: function() { 
        console.log('baseApp created'); 
       }, 

       /* 
       * Initialisation, called after _create and and on later widget calls. 
       */ 
       _init: function() { 
       }, 

       /* 
       * Destructor, cleanup when no longer needed. 
       */ 
       _destroy: function() { 
       } 
     }); 
} (jQuery)); 



/**************************** 

Textbox Widget 

     Requires jQuery 
     Requires jQuery UI 

****************************/ 

(function($, undefined) { 
     'use_strict'; 



     /* 
     * A widget 
     */ 
     $.widget('sb.textboxesApp', $.sb.baseApp, { 
       /* 
       * Widget Option 
       */ 
       options: {}, 



       /* 
       * Constructor, called once when first created 
       */ 
       _create: function() { 
        console.log('textboxesApp create'); 
        return this._super(); 
       }, 

       /* 
       * Initialisation, called after _create and and on later widget calls. 
       */ 
       _init: function() { 
       }, 

       /* 
       * Destructor, cleanup when no longer needed. 
       */ 
       _destroy: function() { 
       } 
     }); 
} (jQuery)); 

jQuery.sb.textboxesApp(); 
+0

非常感谢!这解决了我的问题;) – 2015-01-16 09:18:22