locked
Incrimental Loading With WinJS.UI.Listview

    Question

  • Hi,

    I am trying to create a incremental Loader with WinJS.UI.Listview.

    But unfortunately the "itemsFromIndex" event is getting called infinitely and its ending on a error.

    I adding my code with this, please anyone help me to solve this.

    (function () {
    
        var myNotificationDataProvider = WinJS.Class.define(
            function () {
    
                // Constructor
                this._minPageSize = 20;
                this._maxPageSize = 20;
                this._maxCount = 1000;
                this._pageIncrementer = 1;
            },
    
    
            {
    
                getCount: function () {
                    var that = this;
                    var Protocol = AppLocalSettingCollection.protocol;
                    var UrlDomain = AppLocalSettingCollection.accessUrl;
                    var access_token = AppLocalSettingCollection.access_token;
                    var device_id = AppLocalSettingCollection.device_id;
                    var subDomain = AppLocalSettingCollection.subDomain;
                    var learningContentForReviewURL = Protocol + subDomain + "." + UrlDomain + API_URLSCHEME.GET_USERNOTIFICATION + "?lang=9cfefed8fb9497baa5cd519d7d2bb5d7&access_token=" + access_token + "&deviceid=" + device_id + "&sentbyme=0&page=" + MyNotification.currentPage + "&limit=20";
                    return WinJS.xhr({ url: learningContentForReviewURL }).then(
                           function completed(response) {
                               var requestResult = JSON.parse(response.responseText);
                               that._maxCount = requestResult.notifyCount;
                               return requestResult.notifyCount;
                           },
                           function error(error) {
                               var pp = '';
                           },
                           function progress(progress) {
                           });
    
                },
    
    
                itemsFromIndex: function (requestIndex, countBefore, countAfter) {
                    var that = this;
                    if (requestIndex >= that._maxCount) {
    
                        return WinJS.Promise.wrapError(new WinJS.ErrorFromName(WinJS.UI.FetchError.doesNotExist));
    
                    }
                    else {
                        var fetchSize, fetchIndex;
                        if (countBefore > countAfter) {
                            countAfter = Math.min(countAfter, 20);
                            var fetchBefore = Math.max(Math.min(countBefore, that._maxPageSize - (countAfter + 1)), that._minPageSize - (countAfter + 1));
                            fetchSize = fetchBefore + countAfter + 1;
                            fetchIndex = requestIndex - fetchBefore;
                        } else {
                            countBefore = Math.min(countBefore, 20);
                            var fetchAfter = Math.max(Math.min(countAfter, that._maxPageSize - (countBefore + 1)), that._minPageSize - (countBefore + 1));
                            fetchSize = countBefore + fetchAfter + 1;
                            fetchIndex = requestIndex - countBefore;
                        }
    
    
    
    
                        var Protocol = AppLocalSettingCollection.protocol;
                        var UrlDomain = AppLocalSettingCollection.accessUrl;
                        var access_token = AppLocalSettingCollection.access_token;
                        var device_id = AppLocalSettingCollection.device_id;
                        var subDomain = AppLocalSettingCollection.subDomain;
                        var learningContentForReviewURL = Protocol + subDomain + "." + UrlDomain + API_URLSCHEME.GET_USERNOTIFICATION + "?lang=9cfefed8fb9497baa5cd519d7d2bb5d7&access_token=" + access_token + "&deviceid=" + device_id + "&sentbyme=0&page=" + that._pageIncrementer + "&limit=20";
                        that._pageIncrementer += 1;
                        return WinJS.xhr({ url: learningContentForReviewURL }).then(
                               function completed(response) {
                                   var requestResult = JSON.parse(response.responseText);
                                   that._maxCount = requestResult.notifyCount;
                                   var results = [];
                                   for (var i = 0, itemsLength = requestResult.arrNotificationDetails.length; i < itemsLength; i++) {
                                       var dataItem = requestResult.arrNotificationDetails[i];
                                       results.push({
                                           key: (fetchIndex + i).toString(),
                                           data: dataItem
                                       });
                                   }
    
                                   return {
                                       items: results, 
                                       offset: requestIndex - fetchIndex, 
                                   };
    
    
                                   return requestResult;
                               },
                               function error(error) {
                                   var pp = '';
                               },
                               function progress(progress) {
                               });
                    }
                }
            });
    
        WinJS.Namespace.define("myNotificationDataPropviderIncrementListing", {
            datasource: WinJS.Class.derive(WinJS.UI.VirtualizedDataSource, function () {
                this._baseDataSourceConstructor(new myNotificationDataProvider());
            })
        });
    })();
    

    The DataBinding is getting completed successfully, but due to the error the app is getting crashed.

    I am also attaching the screen shot of the error with the post.

    Sunday, April 20, 2014 10:50 AM

All replies

  • 1) What is calling itemsfromindex repeatedly?

    2) If you check for null before trying an operation, it would prevent the exception.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, April 21, 2014 1:13 PM
    Moderator