javascript - jQuery Plugin return Values through options function -


i'm making own jquery plugin (i still learning!). plugin needs return values once clicked on element.

it looks along lines of this:

$.fn.testplugin = function(options) {      var defaultoptions = {         values: {             value1: "",             value2: ""         },         ondivnameclick: function() {}     };     options = $.extend(true, defaultoptions, options);      //do initializing here      divname.click(function () {          //do other plugin stuff on click here          // onclick user function         if ($.isfunction(options.ondivnameclick)) {             options.ondivnameclick.call(options.values);         }     })      //other code here.       return this; } 

i initialize plugin , pass commands executed plugin not return values need through values instead 'undefined'.
debugging shows me options.values have data inside plugin i'm not entirely sure correct way it.

$("#elname").testplugin({     ondivnameclick: function (values) { //values returns 'undefined'         model.value1 = values.value1;         model.value2 = values.value2;     },     option1: "",     //other options }); 

ondivnameclick should pass options.values function in options not. doing wrong?

the javascript prototype.call() method needs 1 more parameter referring this.

if ($.isfunction(options.ondivnameclick)) {     options.ondivnameclick.call(this, options.values); } 

because of - no actual values passed through function.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -