本文介绍了流星下拉列表获取并设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Meteor中从下拉列表(以及在广播中)中获取和选择值的最佳方法是什么. 我创建了一个助手:
What is the best way to get and select values from a dropdown list (and also in radio) in Meteor. I have created a helper:
Template.categories.helpers({ categories: ["facebook", "news", "tv", "tweets"] });和html
... <select class="form-control" id="category"> {{> categories}} </select> ... <template name="categories"> <option disabled="disabled" selected="selected">Please Select</option> {{#each categories}} <option value="{{this}}">{{this}}</option> {{/each}} </template>在进行编辑的情况下,我希望使用来自数据库(例如新闻)的值进行评估.
In case of edit, I would like to evaluate it with value coming from database (e.g. news) to be selected.
谢谢.
推荐答案模板HTML:
<select id="category-select"> <option disabled="disabled" selected="selected">Please Select</option> {{#each categories}} <option value="{{this}}">{{this}}</option> {{/each}} </select>模板js:
Template.categories.helpers({ categories: function(){ return ["facebook", "news", "tv", "tweets"] } }); Template.categories.events({ "change #category-select": function (event, template) { var category = $(event.currentTarget).val(); console.log("category : " + category); // additional code to do what you want with the category } });更多推荐
流星下拉列表获取并设置
发布评论