问题描述
我在页面中编辑,查看,取消功能。
查看
我有重复。在ng-repeat内部,我创建了span,其值来自db。
编辑
编辑功能,我在文本框中显示这些跨度值(输入类型文本)。
现在用户编辑了一个文本框,
编辑完成后,用户将点击保存,将其保存在数据库中。
怀疑:
如果用户点击取消,我需要保留所有已编辑的文本框的旧值。
我尝试使用angular.copy来保留原始数组。然后如果它被取消将用复制的数组替换模型。但是这种方法会影响性能,如果我有这么多单元格,如果只编辑一个单元格则不需要为所有单元格进行角度复制。
i尝试使用ng-change.and我能够获得旧值,但我不想使用ng-change,因为它每次都会被调用,因为我需要获取旧值一次。
所以我想到了ng-focus。因此,一旦文本框被聚焦,将复制数组中的旧值。然后用户编辑文本框。但是如果我们移动到其他文本框并再次返回到上一个文本框,我不想再次调用焦点,因为我已经为该文本框设置了旧值。
那么有没有办法限制焦点功能(javascript函数)一次。
或者我可以使用其他方法吗?
Hi,
I have edit,view,cancel functionality in a page.
view
I have a ng repeat. Inside ng-repeat i am creating span whose value comes from db.
Edit
on edit functionality, I show those span values in textbox(input type text).
Now user edits a textbox,
Once the editing is done, user will click on save,to save it in db.
Doubt:
If user clicks cancel, i need to retain the old value of all the edited textboxes that has come for db.
I tried with angular.copy to keep the original array. then if it is cancelled will replace the model back with the copied array. But this approach impacts performance if i have so many cells, if only one cell is edited no need to do angular copy for all.
i tried with ng-change.and i am able to get the old values, but I don't want to use ng-change as it will be called everytime as i need to get the old value once.
So I thought of ng-focus. So once the textbox is focussed, will copy the old value in an array. Then user edits the text box. But if we move to other textbox and come back again to previous textbox I don't want to call the focus again as i have already the old value for that textbox.
So is there any way to restrict focus function(javascript function) once.
Or is there any other approach which I can use?
推荐答案
这篇关于保留文本框的旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!