敲除ockout.js 1.2.1中的绑定 [英] Suspend bindings in knockout.js 1.2.1

查看:56
本文介绍了敲除ockout.js 1.2.1中的绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在淘汰赛中是否可以选择暂停和恢复绑定?

Is there any option to suspend and resume bindings in knockout?

版本:knockout.js 1.2.1

Version : knockout.js 1.2.1

我们需要暂停绑定的原因如下.在某些操作中,我们必须从服务器加载大量数据,例如,多个选择更改了它们的整个数据,有些表的行是动态添加的,等等.

Our need for suspending bindings stems from the following. During some operations we have to load a lot of data from the server, eg multiple selects have their entire data changed, there are tables whose rows are dynamically added etc.

现在,在当前情况下,表单已与视图模型完全绑定.当我们清除组合并添加每个项目时,视图将刷新,因此会有很大的延迟.如果我有办法暂停绑定,则可以暂停,然后将所有数据加载到视图模型中,然后再次恢复绑定.

Now in this current scenario, the form is fully bound with the view model. When we clear the combos and add each item, the view gets refreshed hence there is significant delay. If I had the means to suspend binding, I could suspend, then load all data into the viewmodel and then resume binding again.

推荐答案

我认为没有方法可以在ockout.js中暂停绑定.没有看到代码很难说,但是速度缓慢可能是由于您通过清除observableArray并逐个添加新项来刷新observableArrays所导致的.相反,您可以一次刷新整个阵列:

I don't think there is a way to suspend binding in knockout.js. Without seeing the code it's hard to say, but the slowness is probably caused by the fact that you refresh you observableArrays by clearing them and adding new items one by one. Instead you can refresh the entire array at once:

...
self.manyItems = ko.observableArray();
...
function refreshItems(newItems){
    self.manyItems(newItems);
}

这篇关于敲除ockout.js 1.2.1中的绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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