Angular edit row & store values in array [closed]

2020-01-25 11:56发布

问题:


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 29 days ago.

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

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 having all row records fetched during ngOnInit

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

Everything is done on Angular 5

回答1:

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

storeArray.reverse();