I’m having problems when accessing a subobject within a Meteor collection dynamically. Let´s say that each document within the collection has the ‘white’, ‘black’ and ‘red’ property.
_id: 123456
propA: 'xxx',
white: {
prop1: 'aaa',
prop2: 'bbb',
prop3: 'ccc´
},
black: {
prop1: 'ddd',
prop2: 'eee',
prop3: 'fff'
},
red: {
prop1: 'ggg',
prop2: 'hhh',
prop3: 'iii'
}
Then the user profile has a favourite color property that matches ‘white’, ‘black’ or ‘red’.
How could I render one property within one of those collections dinamically depending on the user’s favourite color?
I was trying to do something like this (but it is not working):
{{#each collection}}
{{this[Meteor.user().profile.favouriteColor].prop1}}
{{/each}}
where collection comes from the template helper, it just does a Collection.find();
Maybe I should rethink my data model and create different collections for ‘white’, ‘black’ and ‘red’ and subscribe to the corresponding collection? As I’m not finding any other question or people having the same problem it makes me think that I may be following the wrong approach…
Thanks in advance