填充较大的可观察阵列时,我可以加快剔除速度吗? [英] Can I speed up knockout when populating a large observable array?

查看:71
本文介绍了填充较大的可观察阵列时,我可以加快剔除速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,该应用程序对某些数据执行SOAP请求,并使用结果填充剔除视图模型.我目前有大约1000个订单项,这些订单项必须推送到我的剔除视图模型中.在chrome中对页面进行性能分析表明,大部分的加载时间/CPU都花在了ockout.js上.我在徘徊,是否有办法在所有项目都推入可观察数组之前延迟任何敲除更新/处理.

I have a web app that does a SOAP request for some data and populates a knockout viewmodel with the results. I'm currently getting around 1000 line items back that have to be pushed onto my knockout viewmodel. Profiling the page in chrome shows that a large portion of the load time/CPU is spent in knockout.js. I'm wandering if there's a way to maybe delay any knockout updates/processing until all of the items are pushed into the observable array.

为了更加清楚,我想我正在寻找延迟或限制.但是从此答案看来,我可能最好先构建一个普通数组,然后填充整个可观察数组,而不是将每个项目直接推到可观察数组上.这可能消除了我延迟或限制绑定的需要.有什么建议吗?

To be more clear, I guess I'm looking for something like delaying or throttling. But it looks like, from this answer that I might just be better off building a normal array and then populating the entire observable array, instead of pushing each item directly onto the observable array. This might remove my need to delay or throttle bindings. Any recommendations?

推荐答案

如果只需要替换内容,就不需要遍历数组.

If you just need to replace the contents of an observableArray, you don't need to loop through the array.

最有效的操作是简单地将其设置为新值:

The most efficient operation is to simply set it to a new value:

this.obsArray(newData);

这篇关于填充较大的可观察阵列时,我可以加快剔除速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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