更新ViewModels时如何防止Kendo UI Grid重新绑定多次 [英] How to prevent Kendo UI Grid from rebinding many times when updating ViewModels

查看:180
本文介绍了更新ViewModels时如何防止Kendo UI Grid重新绑定多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用MVVM绑定到Kendo UI网格时,数据绑定将触发一次,一切都很好.如果您需要在事后更新该数据,则每次在任何视图模型(或子视图模型)上更改一条数据时,整个网格都会重新绑定数据.因此,如果网格中有一些与模板绑定的单元,并且您必须从某些外部ajax源更改viewmodel的2或3个属性,则对于每个更改的模型,Databound将触发2或3次,从而导致重新绑定整个可见区域.我们如何才能一次更新大量数据,而一次只能触发数据绑定?

When you bind to a Kendo UI Grid with MVVM, databound will fire once and all is well. If you need to update that data after the fact, every time you change one piece of data on any viewmodel (or child viewmodel), the entire grid re-databinds. Thus, if you had some cell in the grid that is bound to a template and you have to change 2 or 3 properties on the viewmodel from some external ajax source, Databound will fire 2 or 3 times for each model that is changed, causing the entire viewable area to rebind. How can we update lots of data at once and only have databound fire once?

推荐答案

您如何精确地重新绑定网格?基本上,如果您更改某些模型,例如:

How exactly you rebind the Grid? Basically if you change some of the models like this:

dataItem.set('SomeField','new value');
dataItem.set('someOtherField','other value');

这样,由于MVVM,网格确实将绑定两次.每次您呼叫设置时都会触发更改事件.

This way the Grid will be indeed bound two times because of the MVVM. The change event is triggered each time you call set.

但是,如果您更新像这样的值:

However if you update the values like this:

dataItem.SomeField='new value';
dataItem.someOtherField= 'other value';

网格将不会对更改做出反应,也不会重新绑定重新读取模型中的值,您可以通过刷新方法强制网格执行此操作.

The Grid wont react to the change and wont rebind re-read the values from the models you can force the Grid to do it through the refresh method.

$('#gridName').data().kendoGrid.refresh()

这篇关于更新ViewModels时如何防止Kendo UI Grid重新绑定多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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