角度编辑行将值存储在数组中 [英] Angular edit row & store values in array

查看:69
本文介绍了角度编辑行将值存储在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将编辑后的行数据与编辑后的行下方的行进行比较。

I need to compare edited row data with the row just below edited row.

一个具有5行的表。当我使用以下代码按顺序从顶部到底部编辑记录时,我能够存储在数组中编辑的值。这里最新编辑的值存储在 storeArray 的最后一个索引中。

A table with 5 rows. When i am editing records from top to bottom in that order using below code i am able to store values that are edited in an array. Here latest edited value is stored at the last index of storeArray.

当我从从下至上编辑记录时 >,最后编辑的记录现在保存在第一个索引处,但我希望在那里。它还应像上面那样保存数据,即最后编辑的值应该出现在数组的最后一个索引上

When i am editing records from bottom to top, the last edited record is now saved at 1st index but i want that there. It should also save the data like above i.e last edited value should be present at last index in the array

类似地,在随机编辑时那么最后编辑的值的顺序也应该在数组的最后一个索引处。

Similarly when it is edited in random order then also last edited value should be at last index of array.

下面是用于获取和保存编辑值的代码

Below is the code used to fetch and save edited values

 const storeArray = _.reduce(this.allValuesArray, function(storeArray, value, key) {
  return _.isEqual(value, this.allValuesArray[key]) ?
  storeArray : storeArray.concat(allValuesArray[key]);      
 }, []);

在单击保存按钮后编辑了几行后,将调用上述方法。

Above method is called after editing few rows when the button Save is clicked.


  • allValuesArray = JSON,其中所有行记录均在ngOnInit期间获取

  • allValuesArray = JSON having all row records fetched during ngOnInit

storeArray =我要在其中存储要编辑的数据的数组

storeArray = The array in which i am storing the data that are being edited

一切都在Angular上完成5

Everything is done on Angular 5

推荐答案

您最终可以尝试 reverse 方法来反转元素中元素的顺序array,例如:

You can try reverse method in the end to reverse the order of the elements in your array , something like:

storeArray.reverse();

这篇关于角度编辑行将值存储在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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