I’m trying to create an online-list for a chat. Whenever a person moves into a room, his nickname gets pushed into the array inRoom, when he leaves it gets pulled out again. This works fine so far. Displaying the arrays on the actual list confuses me though.
A bit of an edge case that you might want to think about in your design is what happens when the user opens multiple windows of the same chat and then closes one. Currently my guess is thay it will not list them as being in the room.
I’m not completely clear about that {{each in}}-helper. I’m trying to understand it by imagining the collection-document of that example.
{{#each todo in todos}}
{{#each tag in todo.tags}}
<!-- in here, both todo and tag are in scope -->
{{/each}}
{{/each}}
So in that case tag would be value of the array? Why is there a plural and singular form of todos? Todo would be the helper word, I guess? Like mine is roomData? I tried to make it like so:
{{#each roomData in roomDatas}}
{{#each inRoom in roomData.inRoom}}
{{roomData.inRoom}}
{{/each}}
{{/each}}
Right now, when someone opens another tab and joins the same room his name gets duplicated. If he closes one both values of his name get deleted. This is an issue I will work on.
If roomDatas is an array that you want to iterate, and when you pass it through #each. It iterates through each value/object in array. Earlier one used ‘this’ for the value/object in scope during iteration loop. Now it gets assigned to a variable in this case(your example) to roomData.
This is helpful when you need to use #each with nested arrays.