-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue: First get uses index 1, whereas array starts at index 0 #44
Comments
Is there an item with index 0 in your dataset? If there is not, it should not prepend anything there. |
Like me, he might have tried to map his dataset into a standard Javascript Array. In my use case, the data is retrieved from a web service which returns a JSON string that is parsed into a standard JS Array. This means that the dataset index is zero based and it will always have an item with index 0, even if i don't use it. |
Yes, I'm using standard 0-based javascript arrays. Should I not? |
You can use anything - 0 based arrays included, it does not change the logic on what items are sent back in the responses. Assuming the you have and items[20] array the scroller is going to call get as follows: Keep in mind that as you scroll up and down the start index can change to pretty much anything, so the math selecting the array subset although simple is somewhat confusing. You can check the examples i.e. this one |
I just decremented the index before doing any selection to respond. So, for an array with length==20 : What i don't understand is really why? |
Yea, it should work. You just should also be prepared to handle the requests with any start index between -9 and 20 |
Just for completeness and considering the array has all the data: --index; // ...
endItem = index + count;
startItem = (index<0?0:index);
this.data.slice(startItem, endItem) |
Yes this is exactly the solution I came up with, however, it doesn't work with all viewport sizes. |
You also need to account for the case when index+count goes out of bounds |
But what do I do in that case? |
that's what worked for me: |
Is there any reasoning behind this?
The problem is ui scroll starts loading from index 1, then shortly after prepends the element at index 0. This results in the container being scrolled down slightly on initial page load.
I tried just subtracting 1 from index before fetching elements from my array, but this can result in a situation where the requested index is -10 and count is 10 (total 0 elements requested) which means it will stop asking for more.
The text was updated successfully, but these errors were encountered: