kendo UI网格数据项设置方法 [英] kendo UI grid dataitem set method
问题描述
grid.dataItem(selectedRow)
这将返回所选行,即kendo.data.ObservableObject.
this is return the selected row which is a kendo.data.ObservableObject.
此对象具有该网格的所选行的所有列.有没有一种方法可以遍历所有列并进行更新. 还是我必须这样做:
this object has all the columns for that grid's selected row. Is there a way to iterate thru all the columns and update. or do i have to do it like this:
dataitem.set("Id", 1);
dataitem.set("name", Eric);
dataitem.set("age", 12);
推荐答案
据我了解,您正在尝试将一个JavaScript对象复制到Grid项目中,对吗?
As far as I understand what you are trying is to copy one JavaScript object into a Grid item, correct?
假设您在val
中具有新值:
var val = {
Id : 1,
name: "Eric",
age: 12
};
您想将其复制到所选行中.
And you want to copy it in the selected row.
有几种方法可以做到:
- 你刚刚做了什么.
- 遍历
val
的不同键并复制值. - 使用jQuery扩展.
- What you just did.
- Iterate through the different keys of
val
and copy the value. - Use jQuery extend.
选项2.
for (var key in val) {
if (val.hasOwnProperty(key)) {
dataitem.set(key, val[key]);
}
}
选项3.
$.extend(item, val);
item.set("uid", kendo.guid());
第一条指令将val
的深层副本复制到item
中.
第二条指令仅通过更改UID来使项目dirty
.
The first instruction performs a deep copy of val
into item
.
The second instruction makes the item dirty
by just changing the UID.
注意::您无需使用set
更新每个字段,只需更改一个字段,所有字段都会被更新.
NOTE: You don't need to update every single field using set
, is enough changing one and all will get updated.
这篇关于kendo UI网格数据项设置方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!