剑道UI网格数据项设置方法

剑道UI网格数据项设置方法

本文介绍了剑道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 中有新值:

Let's assume that you have the new value in val:

var val = {
    Id : 1,
    name: "Eric",
    age: 12
};

并且您想将其复制到所选行中.

And you want to copy it in the selected row.

有几种方法可以做到:

  1. 你刚刚做了什么.
  2. 遍历 val 的不同键并复制值.
  3. 使用 jQuery 扩展.

选项 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.

这篇关于剑道UI网格数据项设置方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:45