Meteor Dropdown #each over a collection


#1

I’ve been around this all day and i can’t figure why my each cycle is not working. I’m trying to create a dropdown with some countries.

Helper

Template.register.helpers({
    countries: function(){
        return Country.find({ });
    },
});

View, template register

      <select id="country-select">
        <option disabled="disabled" selected="selected">Please Select</option> 
       {{#each countries}}
            <option value={{ name }}>{{ name }}</option>
        {{/each}}
      </select>

I have records in the country collection

meteor:PRIMARY> db.country.find({ }).count()
4

The only options that the dropwdown displays is the placeholder.


#2

The solution that worked for me is by calling the ‘material_select’ function after the options data has been loaded.

Template.[name].rendered = function() { this.autorun(function() { var optionsCursor = OptionsList.find().count(); if(optionsCursor > 0){ $(‘select’).material_select(); } }); };

from https://github.com/Dogfalo/materialize/issues/1469