Lazy load items with filtering

℡╲_俬逩灬. 提交于 2020-01-14 09:33:03

问题


I am using Backbone.js to load 20 items at a time on the page, getting more items when you scroll down to the bottom until there are none left to fetch from the server.

At the same time, I want an input field up top that as you type a name, it filters the items that match.

The issue is, if you haven't scrolled to the bottom yet and fetched the full set, the input filter will only match the items that are currently on the page.

What is the best solution technically and visually for combining UI filtering with lazy loaded items?

EDIT: The real scenario here is loading all of your facebook friends which can be very slow and mashing them up with other apis. I did not want to load all at once because the experience is delayed.


回答1:


When a user is searching, why not reset the collection with a fetch that includes a filter?

Collection.fetch({ term : $("#search").val()})

If you setup your backend API end point for this collection to scope your results by the term params, then your collection would only contain results from the server that match the user input.

You could also limit the initial fetch to the first 3 characters the user enters then do the rest of your filtering client side as they continue to type. That is if you aren't limiting the search results server side with your first call.



来源:https://stackoverflow.com/questions/11552577/lazy-load-items-with-filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!