【问题标题】:materialized / meteor - select form is not working物化/流星 - 选择形式不起作用
【发布时间】:2018-03-16 00:57:19
【问题描述】:

我正在尝试在我的 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/Screenshot%202015-05-09%2018.24.08.png?dl=0

【问题讨论】:

  • 没有“这个”。它也不能正常工作?
  • 感谢您的回复。正如你所看到的(我编辑了我的问题),有这个显示选择表单,没有这个不显示选择表单......所以没有这个似乎不起作用。

标签: meteor materialized


【解决方案1】:

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

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

如果您正在使用最后一个(在撰写本文时)版本的 materialize (v0.97.2) there is a bug that causes the dropdown not to be generated 固定在 this commit

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

选择会起作用。

【讨论】:

    【解决方案2】:

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

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

    希望有效果

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-01-29
          • 2016-03-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-06-17
          • 1970-01-01
          相关资源
          最近更新 更多