I have created a Controller for an Umbraco API call to retrieve child news Articles. It only takes 4 at a time and there is a "Load More" button to take the next four. So whenever someone selects the "Load More" button it will hit the api for the next 4.
However, i want it to detect when there is no longer any more to get, so i can hide the Load More button. I could do this if the API returns nothing but i would want so it knows when it has retrieved the last one from the foreach loop.
I have tried .IsLast() however, there will always be a "last" item when grabbing 4 at a time. Does anyone know how i can approach this? Do i need to do some kind of nested foreach to grab the inital collection first then a foreach for taking 4 of the parent collection?
Could you extend your returned data model to include a "Is more" flag along with the contents?
Then in your API you can check if currentCount + moreCount is greater than or equal to the total number of children. If it is, you could set the "Is more" flag to be false.
Something to consider though (and I don't know how you want to handle this)... what if someone browses the website, is loading more and at the same time a new article is published? How would your page handle that scenario?
Detect Last item in API Call
Hi,
I have created a Controller for an Umbraco API call to retrieve child news Articles. It only takes 4 at a time and there is a "Load More" button to take the next four. So whenever someone selects the "Load More" button it will hit the api for the next 4.
However, i want it to detect when there is no longer any more to get, so i can hide the Load More button. I could do this if the API returns nothing but i would want so it knows when it has retrieved the last one from the foreach loop.
I have tried .IsLast() however, there will always be a "last" item when grabbing 4 at a time. Does anyone know how i can approach this? Do i need to do some kind of nested foreach to grab the inital collection first then a foreach for taking 4 of the parent collection?
Any help would be really appreciated.
Thanks :)
Query to grab the next 4 items
Hi Gary
Could you extend your returned data model to include a "Is more" flag along with the contents?
Then in your API you can check if currentCount + moreCount is greater than or equal to the total number of children. If it is, you could set the "Is more" flag to be false.
Something to consider though (and I don't know how you want to handle this)... what if someone browses the website, is loading more and at the same time a new article is published? How would your page handle that scenario?
Nik
is working on a reply...