【问题标题】:Meteor Dropdown #each over a collectionMeteor Dropdown #each 在集合上
【发布时间】:2016-11-13 23:39:54
【问题描述】:

我整天都在这个问题上,我不明白为什么我的每个周期都不起作用。我正在尝试创建包含某些国家/地区的下拉列表。

助手

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

查看、模板注册

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

我在国家集合中有记录

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

下拉菜单显示的唯一选项是占位符。

我用的是蒙古语这是一个国家记录

【问题讨论】:

  • 您的Country 对象有name 键吗? HTML 中显示了什么 - 一组空选项或只有禁用的选项?
  • @MichelFloyd 我编辑得最多。但我认为它甚至没有进入每个循环,因为即使我在其中执行类似 之类的操作,我也会得到 0 个结果
  • @MichelFloyd 我试过 {{#each countries}}

    {{name}}

    {{/each}}
  • 它在选择之外工作
  • 感觉像是错字 - 助手名称不匹配,模板名称不匹配。你在做什么应该工作。

标签: meteor handlebars.js materialize


【解决方案1】:

“对我有用的解决方案是在加载选项数据后调用 'material_select' 函数。

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

来自https://github.com/Dogfalo/materialize/issues/1469

【讨论】:

    【解决方案2】:

    试试

    return Country.find().fetch()
    

    在助手中

    谢谢 希望对你有帮助

    【讨论】:

      【解决方案3】:

      试试这个...

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

      在这里工作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多