问题
I have been going through the below Plunker,
plunker link here
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?
- I have tried deleting the row and update the new in the deleted place , but this idea is not correct tmk
Any guiding links or any help is much appreciated ....TIA
回答1:
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; });
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).
回答2:
You should try to work with data binding rather than manually extracting and inserting your values:
https://sapui5.hana.ondemand.com/1.28.33/docs/guide/91f0ca956f4d1014b6dd926db0e91070.html
Nevertheless, if you do want to edit a property of an item in your array, you can edit it as follows:
array[index].property = "new value";
来源:https://stackoverflow.com/questions/60166309/how-to-update-the-rows-of-a-table-using-dialog-box