Chaining not working on jQuery Plugin

ChrisJ

I am writing a plugin to pull listings in from my companies internal API and everything is working except for some reason it will not allow me to chain additional methods.

(function( $ ) {

    $.fn.addListings = function(options){
        var defaults = {
            listingCount: 25,
            pageNumber: 1,
            customTemp: "<div class='listing'>\
            <img src='${IDXPhotoRef}'/>\
            <div class='address'>${Address}</div>\
            <div class='beds'> Beds: ${BedRooms}</div>\
            <div class='baths'>Baths: ${BathRooms}</div>\
            <div class='price'>Price: $${PriceFormatted}</div>\
            </div>",
            after: function(){}
        }

        var settings = $.extend({}, defaults, options );

        $.ajax({
          type: 'GET',
          // url: '/api/listings/?featuredlistings=1&pagesize=' + settings.listingCount + '&pagenumber=' + settings.pageNumber + '',
          url:'data.json',
          contentType: 'text/plain',
          crossDomain: true,
          context: $(this)
          })
        .done(function(data) {
            $.template("customTemp", settings.customTemp);
            var arrData = $.map(data[0], function(el) { return el; });
            for(i=0; i<arrData.length; i++){
                $.tmpl("customTemp", arrData[i]).appendTo(this);
            }

          })
        .always(function(){
            settings.after();
          });

    };

    return this;

    }( jQuery ));

https://github.com/cjthedizzy/jquery.addListingsJS/blob/master/jquery.addListings.js

Rory McCrossan

The return this needs to be placed inside the $.fn.addListings block:

(function($) {
    $.fn.addListings = function(options){
        // var defaults = {
        // ... rest of the code...

        return this;
    };
}(jQuery));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Allow chaining in jQuery plugin

From Dev

Allow chaining in jQuery plugin

From Dev

$this jQuery chaining with .on click function is not working

From Dev

jquery chaining not working in my html with each function

From Dev

jQuery colorbox plugin not working

From Dev

Jquery tablesorter plugin is not working

From Dev

Simple jQuery plugin not working

From Dev

Jquery countdownTimer Plugin not working

From Dev

jQuery UI not working in WordPress plugin

From Dev

Regex not working in jquery validation plugin

From Dev

jQuery slick (carousel) plugin not working

From Dev

Jquery plugin not working with Rails 4

From Dev

CSS for Jquery plugin Chosen is not working

From Dev

jQuery slick carousel plugin not working

From Dev

jQuery UI not working in WordPress plugin

From Dev

jQuery 'swiper' plugin mysteriously not working

From Dev

jQuery validate plugin is working unexpectedly

From Dev

Jquery MultiZoom Plugin Not Working Properly

From Dev

Why is jQuery not working in this wordpress plugin?

From Dev

jQuery Regex Selector Plugin not Working

From Dev

JQuery Plugin File Loading But Is Not Working

From Dev

Why "this" in a jQuery plugin is not working as expected?

From Dev

jquery validation is not working with validate plugin

From Dev

jQuery plugin not working after upgrade

From Dev

jquery custom plugin in joomla is not working

From Dev

jQuery plugin not working - it's appended

From Dev

My JQuery Chosen plugin not working

From Dev

jquery MatchHeight plugin not working as expected

From Dev

Plugin not working with JQuery-3.1.0