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

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

问题描述

我需要将编辑过的行数据与编辑过的行正下方的行进行比较.

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 = 在 ngOnInit 期间获取所有行记录的 JSON

  • 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 方法来反转数组中元素的顺序

You can try reverse method in the end to reverse the order of the elements in your array

storeArray.reverse();

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

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