I try to drop and trim a list to build a pagination system
local function createMap(postId, paramDate) local m = map { id = postId, date = paramDate }; return m; end function get(rec, binName, from, to) if aerospike:exists(rec) then local l = rec[binName] if (l == nil) then return nil else local length = #l; if (length <= 10 and to <=10) then return l; elseif (to >= length) then local drop = list.drop(l, from); return drop; else list.trim(l, to);--Remove all elements at and beyond a specified position in the List. list.drop(l, from); --Select all elements except the first n elements of the List return l; end end else return nil;--end return empty array end--end else aerospike exists end
my list has this structure :
[{"date":"2016-01-02T19:45:00.806Z", "id":"568828bc49017f16659f6978"}, {"date":"2016-01-02T19:44:56.040Z", "id":"568828b849017f16659f6977"},...]
It seems that I can't trim and then drop a list. with 21 elements for example : it first return to element 21 to element 13 , then element 21 to element 4 , then element 3 to element 1
my function in node.js is simple for change 'from' and 'to' I send the 'page' fromm the frontend to node.js and use this function :
var skip = 9 * (page -1); var lastIndexToReturn = skip + 9 + 1;
so in first request from and to are '0' and '10', then '9' and '19', etc by using list.trim and list.drop I thought that I can build a pagination system