Question

var lazyLoadList = {
  zeroResult:'',
  loadList:function(url,templateName,callbackaction,divId){
        this.zeroResult = false;
        $(document).endlessScroll({
            //pagesToKeep: 10,
            fireOnce: false,
            callback: callbackaction,
            ajaxUrl: url,
            templateName: templateName,
            divIdToUpdate: divId,
            ceaseFireOnEmpty:true,
            ceaseFire: function(i, p) {
               return this.zeroResult;
            }, 
            intervalFrequency: 5
        });
    },
   getlist:function(fireSequence, pageSequence, scrollDirection, ajaxUrl, templateName, divIdToUpdate){


        if (pageSequence > 1) {
            var requestUrl = ajaxUrl + pageSequence;
            $.ajax({
                url: requestUrl,
                dataType: 'json',
                complete: function() {
                },
                success: function(response){
                   if (response != '0'){
                        var template = $("#"+templateName).html();
                        detailView = Mustache.render(template, response.data);

                        $("#"+divIdToUpdate).append(detailView);
                        //serviceListTemplateDiv
                    }else{
                        this.zeroResult = true;
                    }
                }
            });
         }
     }  

};

In the above code I am jQuery endless scroll plugin. I have two questions regarding the above code:-

1- How to call ceaseFire when this.zeroResult is true?

2- How to stop callback when scrolled in upward direction, like I have handled this using if (pageSequence > 1) {} in the above code?

Was it helpful?

Solution

Use lazyLoadList.zeroResult instead of this.zeroResult

Class names are important and should be used to call/ access variables and methods

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top