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

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

问题描述

当您使用 MVVM 绑定到 Kendo UI Grid 时,数据绑定将触发一次并且一切正常.如果您需要事后更新该数据,每次更改任何视图模型(或子视图模型)上的一条数据时,整个网格都会重新绑定数据.因此,如果您在网格中有一些绑定到模板的单元格,并且您必须从某个外部 ajax 源更改视图模型上的 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,Grid 确实会被绑定两次.每次调用 set 时都会触发 change 事件.

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';

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

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天全站免登陆