Is this helper not reactive? the select box stays blank


#1

Hi,

Do you maybe understand why the selection box stays empty the first time I start Meteor?

<div class="ui selection dropdown">
            <input type="hidden" id="currentUser">
            <i class="dropdown icon"></i>
            <div class="default text">User</div>
            <div class="menu">
                {{#each users}}
                <div class="item" data-value="{{name}}" data-text="{{name}}">
                    <i class="male icon"></i> {{name}}
                </div>
                {{/each}}
            </div>
        </div>

thank you!


#2

I am now using a session var. You can see in the log, the array is being populated in the second run:

I store this in a session var, so why does my helper not rerun and fill the dropdown?

Template.OEMPartner.onRendered(function() {
    this.$(".dropdown")
        .dropdown();

    var usersArray = [];
    var customers = Customers.find()
        .fetch();
    customers.map(customer => { //flatten the array of users over all documents into a single array
        for (var user of customer.users) {
            usersArray.push(user);
        }
    });
    console.log('We obtained the following users out of the customers: ');
    console.log(usersArray);
    Session.set('usersArray', usersArray);
});

#3

So you have a users helper? I don’t see the data context in what you have posted.


#4

sorry, that was

Template.OEMPartner.helpers({
    users() {
        return Session.get('usersArray');

#5

This also works, but I don’t like that I have to pollute my html with logic, or is this the normal way you can present an array in a sub document?

(I now iterate over the customers document, in which a users array is present

   {{#each customers}} {{#each users}}
                        <div class="item" data-value="{{name}}" data-text="{{name}}">
                            <i class="male icon"></i> {{name}}
                        </div>
                        {{/each}} {{/each}}

helper

customers() {
        return Customers.find({}, { sort: { checked: -1 } });
    },

On the other hand, it is much shorter then the whole hassle of making a session var etc…