kendo UI网格数据项设置方法 [英] kendo UI grid dataitem set method

查看:78
本文介绍了kendo UI网格数据项设置方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

有几种方法可以做到:

  1. 你刚刚做了什么.
  2. 遍历val的不同键并复制值.
  3. 使用jQuery扩展.
  1. What you just did.
  2. Iterate through the different keys of val and copy the value.
  3. 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屋!

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