我正在尝试在 Meteor 上使用 Materialise Forms。在其 Materialize 的页面上,它说我应该像这样初始化“选择”输入字段:
$(document).ready(function() {
$('select').material_select();
});
我试过在 Meteor.startup、Template.body.created 上调用它——没有任何效果。我收到以下错误:
undefined is not a function (evaluating '$('select').material_select()')
我应该在哪里初始化它?
最佳答案
使用模板的.rendered
callback
<template name="hello">
<select><option>...</option></select>
</template>
然后你可以在你的js文件中有这个
Template.hello.onRendered(function() {
$('select').material_select();
});
模板很可能在渲染已经触发后添加到主体,这就是渲染主体不起作用的原因。如果您使用 .created
,则 DOM 尚未呈现。
关于javascript - 使用 Materialise 和 Meteor 时应该在哪里初始化 select?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28783887/