JQuery UI: How to call a widget function with its namespace

后端 未结 3 1558
半阙折子戏
半阙折子戏 2021-02-05 08:44

I created two custom JQuery UI widgets with same name but with different namespaces as given below: First widget:

$.widget(\'finance.dialog\',{....}); // this wa         


        
3条回答
  •  礼貌的吻别
    2021-02-05 09:26

    I had the same question, but I don't think it's possible to invoke a jquery ui widget with the namespace.

    If I understand correctly from this: http://bugs.jqueryui.com/ticket/7489 By defining widgets with the same name, it's by design to overwrite earlier definitions. Because regardless of namespace, the widgets are mapped with their name to $.fn.

    As suggested in the bug ticket you can use the bridge function to create a unique mapping to the specific namespaced widget and call it using the unique name.

    In your case, it can be like this:

    $.widget.bridge( "finance_dialog", $.finance.dialog );
    $.widget.bridge( "hr_dialog", $.hr.dialog );
    
    // then call it with...
    $( "div#something" ).hr_dialog(); 
    

    I suppose another way would be to create unique widget names in the first place.

提交回复
热议问题