0

我正在尝试在我的 Meteor 应用程序上使用物化选择表单,但它似乎不起作用....

这是我的代码:

html

<template name="createAutomatedaction">
    <div class="input-field col s12">
      <select>
        <option value="" disabled selected>Choose your option</option>
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
      </select>
      <label>Materialize Select</label>
    </div>
</template>

js

Template.createAutomatedaction.onRendered(function(){
  this.$('select').material_select();
});

当我单击选择表单时,下拉菜单不显示。谁能告诉我我错过了什么?您的帮助将不胜感激。

这个 https://www.dropbox.com/s/nzh7sp5x7by6e1t/Screenshot%202015-05-09%2018.20.54.png?dl=0

没有这个 https://www.dropbox.com/s/e1asl3y5pbtg5yp/Scr​​eenshot%202015-05-09%2018.24.08.png?dl=0

4

4 回答 4

1

初始化选择的正确代码是这样的(假设“createAutomatedaction”是您的模板名称)

Template.createAutomatedaction.onRendered(function() {
  $('select').material_select();
});

如果您使用的是 materialize (v0.97.2) 的最后一个(在撰写本文时)版本,则存在一个导致在此提交上无法生成下拉列表的错误

如果您想手动快速修复它,请从他们的 repo (dist/js/materialize.js) 中获取未缩小的 js,并将 '$body' 的每个实例替换为 'bodyElement' 并使用它。

选择将起作用。

于 2015-11-16T02:32:15.610 回答
0

将您的 jquery 代码放在模板事件中:

Template.templatename.events({
      this.$('select').material_select();
});

希望它有效

于 2015-10-31T09:54:21.640 回答
0

添加标签对我有用class="browser-default"select

于 2016-03-13T21:24:23.343 回答
-1

我删除class="input-field"了它,它对我有用。

于 2018-03-15T16:51:15.467 回答