Accessing widget instance from outside widget

后端 未结 4 540
一生所求
一生所求 2020-12-25 12:16

This is a simple widget mock:

(function ($) {

    $.widget(\"ui.myDummyWidget\", {

        options: {
        },

        _create: function () {
        },         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 12:50

    You can also use the jQuery custom selector to find the widget elements before calling data on them to get the actual widget instance e.g.

    $(this.element).find(":ui-myDummyWidget").each(function (index, domEle) {
        var widgetObject = $(this).data("myDummyWidget");
        widgetObject.hide();
        // this == domEle according to the jQuery docs
    });
    

    That code finds all of the instances of ui.myDummyWidget (note the change of period . to hyphen - ) that have been created and attached to another widget holder.

提交回复
热议问题