Imagine having a JavaScript dynamic array retrieved from a database:
customers = [{'id':1, 'name':'John'},{'id':2, 'name':'Tim}, ...]
Accompanied by input fields:
<input type='text' name="forJohnOnly" ng-model="customers[0].name" />
<input type='text' name="forTimOnly" ng-model="customers[1].name" />
The initial order of the array always places John as the first element. However, there's concern about potential discrepancies if the sort order is altered in the database without reflecting the change in the UI. Subsequently, when the data is sent back to be saved in the database.
An attempt is being made to address this issue dynamically without resorting to creating an additional array solely for indexing purposes and copying between them.
<input type='text' name="forJohnOnly" ng-model="customers[where customers.id=1].name" />
<input type='text' name="forTimOnly" ng-model="customers[where customers.id=2].name" /> (using id due to possible name changes)
Any suggestions or solutions?
Update:
Although the data resides within an array, the text boxes are not uniformly arranged like a grid.