I am trying to establish a connection between two objects in the same array to indicate that one task must be completed before the other can begin. I attempted to use AngularJS's ng-options directive by setting the child object as a property of the parent object using ng-model. This method successfully created a reference to the child object within the parent object, allowing changes made to the child object to reflect in the parent object rather than duplicating it.
However, I am now encountering two challenges:
- When it comes to recreating the array between sessions, I plan to store the data in a database and/or local storage. Would it be best to assign a unique ID to each object and use that ID to set the property during the loading sequence? Should I utilize Angular's private $$hashkey property for this purpose, or would it be better to create my own "primary keys" for these objects? (I may need to do that eventually regardless)
- While setting the child object as a property of the parent object works well, I am unsure how to go about looking up the parent object when I am working with the child. Would I need to iterate through the entire array and find the ID that matches in order to locate the parent object?
Any advice would be greatly appreciated. Thank you.