Skip to content

Commit

Permalink
v0.0.3
Browse files Browse the repository at this point in the history
* Update to allow access  nested object of response data source by using string.
  • Loading branch information
ve3 committed Feb 24, 2021
1 parent 35df648 commit 13eea29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rundiz-scroll-pagination",
"version": "0.0.2",
"version": "0.0.3",
"description": "Scroll down the page and automatically call to get next page contents.",
"main": "index.js",
"directories": {
Expand Down
10 changes: 7 additions & 3 deletions src/RundizScrollPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @author Vee W.
* @license MIT.
* @version 0.0.2
* @version 0.0.3
*/


Expand Down Expand Up @@ -180,12 +180,16 @@ class RundizScrollPagination {
}
headers = undefined;

if (response[thisClass.ajaxDataSrc] && response[thisClass.ajaxDataSrc].length > 0) {
// @link https://stackoverflow.com/a/43849204/128761 Original source code for access sub properties by string.
let responseSource = thisClass.ajaxDataSrc.split('.').reduce(
(p,c)=>p&&p[c]||null, response
);
if (responseSource && responseSource.length > 0) {
// if there are items after XHR.
// append pagination data element.
thisClass.appendPaginationDataElement();
// set next start offset.
thisClass.currentStartOffset = parseInt(thisClass.currentStartOffset) + parseInt(response[thisClass.ajaxDataSrc].length);
thisClass.currentStartOffset = parseInt(thisClass.currentStartOffset) + parseInt(responseSource.length);
// mark calling to false to allow next pagination call.
thisClass.callingXHR = false;// move in here to prevent ajax call again when there are no more data.
}
Expand Down

0 comments on commit 13eea29

Please sign in to comment.