Knockoutjs-对大型observablearray进行排序 [英] Knockoutjs - Sorting a large observablearray

查看:107
本文介绍了Knockoutjs-对大型observablearray进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个带有可观察数组的页面上定义了一个剔除模型.我想使用按钮按不同的属性对数组进行排序,我有一个可行的"解决方案,但是对于大型数组,它的运行速度非常慢.

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/

jsFiddle - http://jsfiddle.net/7JNrc/

按特定属性对可观察到的对象阵列进行排序的最有效方法是什么?

What is the most efficient way to sort a knockout observable array of objects by specific properties?

推荐答案

您的解决方案运行缓慢,并非归因于排序.这很慢,因为您将很多项目绑定到一页上.渲染200个项目要花费很多时间.此外,您的解决方案不是用户友好的.在没有分页和搜索的情况下使用大列表是非常不舒服的.

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

这篇关于Knockoutjs-对大型observablearray进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆