I wish to set a relationship between two objects within the same array, for the purpose of noting that one task must be completed before the other can start. I tried using AngularJS's ng-options directive, setting the child object as a property of the parent object using ng-model. This successfully set the property as a reference to the child object (as in, editing the child object would make the changes appear within the parent object, rather than just duplicating it).
Now I face two problems:
- Recreating the array between sessions- I'm going to be storing the data in a database and/or localstorage. I probably need to store a unique ID for each object and lookup and set that as the property during the load sequence. Is that the best way? Would Angular's private $$hashkey property be appropriate for that or should I make my own "primary keys" for these objects? (I'll have to do that eventually anyway)
- Setting the child object as a property of the parent object is all well and good, but what if I'm on the child and want to look up the parent? Would this just be a question of looping through everything in the array and finding the ID that matches?
Thank you