jquery - how to call a function with parameters inside a widget-factory plugin?
-
I want to call a function inside my jquery-plugin (widget-factory based). Looks like this: (function( $, window) { $.widget("mobile.multiview",$.mobile.widget, { stackUp: function (source, event, data) { ... } } }) (jQuery,this); I want to call stackUp from outside of the plugin. The problem: I don't know how to pass the parameters correctly. This does not work: $('#trigger').multiview("stackUp('pagination', fakeEvent, fakeData)"); Can somebody point me to the correcty syntax of calling a public function inside a plugin and passing along parameters? UPDATE: I can call the function like this: $('#trigger').multiview('stackUp'); but how can I pass the parameters?
-
Answer:
Ok, after endless meddling, the parameters or arguments are passed like this: $("#trigger").multiview('stackUp','pagination', fakeEvent, fakeData ); You just have to add parameters after the function separated by comma. Hope this helps someone else, too.
frequent at Stack Overflow Visit the source
Other answers
I'm not very familar with jquery but try this: $("#trigger").multiview(function() {stackUp('pagination', fakeEvent, fakeData);}); This is an allonymous function which will be executed on need with your static and dynamic parameters.
rekire
I dont really know how that plugin extends and exposes its functions but I would guess you could try one of the following: $.mobile.widget.stackUp.apply($('#trigger'), ['pagination', fakeEvent, fakeData]); $.mobile.multiview.apply($('#trigger'), ['pagination', fakeEvent, fakeData]); However its entirely possible that they don't expose that method. Do you have the code somewhere? UPDATE After actually finding out what this plugin is I read up on the docs and you should be able todo: $('#trigger').stackUp(...) View source here: http://jqueryui.com/demos/widget/default.html - and look at the random function that is defined. Alternatively you could just define the function in a more global scope and then use it as part of the config object and when you want to apply it to specific elements.
nav
Related Q & A:
- How to call a popup from a link inside another popup?Best solution by stackoverflow.com
- How to call a function with parameter in a bash script?Best solution by tldp.org
- How to fire a function before and after automatically in a jquery plugin?Best solution by catchmyfame.com
- how to call a function in Python in another function?Best solution by Yahoo! Answers
- How to call a function asynchronously in PHP?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.