javascript - how to indicate that there are no more items to return from server knockout js -


i returning 200+ items database , display find out when there no more items return because using in scroll-load feature , tell user when reached end.

next - next batch of users

next = function () {     var _page = $.views.roster.viewmodel.currentpage() + 1;     $.views.roster.getpage("/api/roster", 9, _page); };  $.views.roster.getpage = function (url, id, pagenumber) {         $.grain.ajax.get({             url: url,             datatosubmit: { pagenumber: pagenumber, id: id },             datatype: "json",             onsuccess: function (data, status, jqxhr) {                 $.views.roster.rosterviewmodel.addusers(data);                 $.views.roster.viewmodel.currentpage(pagenumber);             }         });     }; 

let me know if provide anymore information.

you either:

if in control of returned json and format modifiable (e.g. it's not sort of publicly accessible web service), modify returned response contain desired info additional field.

{    users: [...your list of users data],    hasmoredata: true } 

or...

assuming data returned in fixed-length batches, check length of returned batch, , if it's shorter expected length, consider mark there no more item (this exposes potential call empty result if total records exact multiple of batch length):

if (usersdata.length < max_batch_length) {    hasmoredata(false); } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -