如何使用对话框更新表的行 [英] How to update the rows of a table using dialog box

查看:39
本文介绍了如何使用对话框更新表的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在经历下面的Plunker,

I have been going through the below Plunker,

plunker 链接在此

这里如果我尝试编辑,新记录会添加到上面而不是更新当前记录,

Here If I try to edit , the new record is added above instead of updating the current ,

如何更新同一示例的当前编辑行而不是添加新行?

How can I update the current edited row for the same example instead adding a new one?

  • 我尝试删除该行并在已删除的地方更新新的行,但这个想法不正确 tmk

非常感谢任何指导链接或任何帮助....TIA

Any guiding links or any help is much appreciated ....TIA

推荐答案

从你的代码我了解到你想要更新模型(变量 aData).使用数据绑定会是一个更好的主意,但如果你想编辑它,你可以使用:

From your code I understand you want to update the model (variable aData). It would be a better idea to use data binding but if you want to edit it you can use:

aData.map(function(item) { 
if (item.ID==id){
    item.Name = name;
    item.Age = age;
    item.Salary = sal;
}
return item; });

这可能不是执行此操作的有效方法,它认为您具有唯一的 ID.也不要使用 unshift() 函数,因为它会添加新值(不会更新现有值).上面添加的记录是因为您实际上添加了一个新元素(请参阅 link).

This is probably not the efficient way to do it and it consider you have unique ids. Also don't use the function unshift() because it add new value (doesn't update the existent).The record is added above because you actually add a new element (see link).

这篇关于如何使用对话框更新表的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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