Ian Benoliel
Ian Benoliel

Reputation: 67

arguments for callback in jquery plugin are undefined

How do you call a function function defined outside a plugin but using arguments inside the plugin. I have it where the plugin is calling the function but the parameters are undefined. Inside the plugin the arguments has values.

(function ($) {
    $.fn.myPlugin = function (options) {
        var defaults = {
            type: 0,
            callBack: function () { }
        };
        var settings = $.extend({}, defaults, options);
        this.find('.list-item').click(function (e) {
            e.preventDefault();
            var txt = $(this).attr('href');
            var id = txt.substring(1, txt.length);
            settings.callBack.call(settings.type, id);  // populated here
        });
        return this;
    };
} (jQuery));

function loadData(type, id) {
    // type and id are undefined
}

<script type="text/javascript">
     $(document).ready(function () {
        $("#mydiv").myPlugin({ 
            type: 190, 
            callBack: function(){ loadData();}
         });
     });
</script>

Upvotes: 0

Views: 120

Answers (2)

Bene
Bene

Reputation: 1905

What if you replace

callBack: function(){ loadData();}

By

callBack: loadData

Hope that helps

Upvotes: 1

kfa
kfa

Reputation: 2146

loadData() doesn't provide any arguments while type and id are expected

Upvotes: 0

Related Questions