问题
I have a knockout model defined on a page with an observable array. I would like to have buttons to sort the array by different properties, I have a 'working' solution but it is extremely slow for large arrays.
jsFiddle - http://jsfiddle.net/7JNrc/
What is the most efficient way to sort a knockout observable array of objects by specific properties?
回答1:
Your solution is slow not due to the sorting. It is slow because you bind a lot of items to one page. It takes much time to render 200 items. Moreover your solution is not user friendly. It is very uncomfortable to work with big list without pagination and searching.
So my advice is to use pagination in your list. In this case you will not have any performance issues.
Here is an example of simple client side pagination: Client-Side Pagination
来源:https://stackoverflow.com/questions/12743265/knockoutjs-sorting-a-large-observablearray