我是 Meteor 新手。我正在使用 Meteor-x-editable-bootstrap 创建一个下拉列表,其选项必须使用 Mongo 集合中的数据填充。
现在,我的代码是:
$('#options').editable({
type: 'select',
source: [
{text: 'Option 1'},
{text: 'Option 2'},
{text: 'Option 3'}
]
});
这些是硬编码值(“选项 1”、“选项 2”等)。现在,我有一个集合 Options
,其中有一个字段 Values
。如何动态设置 source
数组以从集合中检索数据?请帮忙!!
最佳答案
菜单的 meteor 模式根本不需要 jQuery。在您的模板中,您只需迭代集合即可创建菜单:
<template name="myMenu">
<select #id="mySelect>
{{#each item}}
<option value={{_id}}>{{name}}</option>
{{/each}}
</select>
</template>
那么你只需要一个助手来返回你需要的项目:
Template.myMenu.helpers({
items() {
return MyCollection.find();
}
});
还有一个事件处理程序:
Template.myMenu.events({
'onChange #mySelect'(ev) {
...handle the event.
}
});
关于javascript - 在 Meteor 中加载带有收集数据的选择输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477115/