Meteor Dropdown #each over a collection

时间:2016-07-11 21:58:28

标签: meteor handlebars.js materialize

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.

I'm using mongol this is a country record

enter image description here

3 个答案:

答案 0 :(得分:1)

Try this...

 <option disabled selected>Please select</option>
 {{#each countries}}
     <option>{{name}}</option>
 {{/each}}

It works here

答案 1 :(得分:1)

"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

答案 2 :(得分:1)

尝试

return Country.find().fetch()

在帮手

由于 希望它有所帮助