Calling public methods with jQueryUI Widget parameters

I am currently using jQuery widget jget servers, and I kind of hit in a call to public methods with a parameter.

This is what I did.

//Widget $.widget('ui.MyWidget',{ public_method_without_params: function(){ //do something; } public_method_with_params: function(word){ //do something; } }); 

I am trying to call public_method from the outside. If it has no parameter, I would do either

(i) $('#some-element').MyWidget("public_method_without_params")

(or)

(ii) $('#some-element').data("MyWidget").public_method_without_params();

Is it possible to call public_method_with_params similar to the above (i)?

Thanks.

+4
source share
2 answers

Currently I have done this:

 $('#some-element').data("MyWidget"). public_method_with_params(word); 

and it works. The only problem is that I need to initialize "MyWidget" before that.

 $('#some-element').MyWidget() 
+1
source

You can. The syntax (I believe) is as follows:

 $('#some-element').MyWidget("public_method_with_params", word); 
+6
source

Source: https://habr.com/ru/post/1401306/


All Articles