I'm currently working on setting up a property within an object that will also be an object itself. For example, let's say I have a property named 'cities' and I want to assign populations to different cities within this object.
cities: {
'city1': 100,
'city2': 200
}
If I need to add another city, like 'city3', I can simply do:
this.get('cities')['city3'] = 300
However, although this updates the object, it does not update the bindings as desired. While I could convert the object into an array and use pushObject
, ideally I would prefer a method where when inputting data about a particular city, if it already exists, it would just update the old data rather than create duplicates.
Is there a way to achieve this functionality while still maintaining observability?
Thank you.
Even utilizing:
this.set('cities.city1',100)
does not trigger notifications for changes since I am unable to observe @each. To work around this issue, I ended up using a trick mentioned in this answer.
Observe properties on nested object