javascript - How to obtain x objects with highest timestamp value? -
i'm new web app development , couldn't find solution following problem. i'm trying sorted array of newest objects indexeddb database. each object contains timestamp value. i'v created index on timestamp , i'm able object highest value.
function getmails (numberofmessages, _function) { /* function uses asynchronous methods, hence have pass key , function receive messageitem parametr */ if (typeof optionalarg === 'undefined') { optionalarg = 10; } function _getmails (db) { var transaction = db.transaction(["messageitem"], "readonly"); var store = transaction.objectstore("messageitem"); var index = store.index("timestamp"); var cursor = index.opencursor(null, 'prev'); var maxtimestampobject = null; cursor.onsuccess = function(e) { if (e.target.result) { maxtimestampobject = e.target.result.value; _function(maxtimestampobject); } }; } opendb(_getmails); }
function opendb opens database , passes db object _getmails function parametr. function getmails passes object highest timestamp value. iterate on databse x(numberofmessages) times , allways select object highest timestamp while excluding objects in array i'm trying get. i'm not sure if it's convenient way so. thank responses. jan
you need call cursor.continue()
in onsuccess
function. called again next cursor result.
Comments
Post a Comment