流星下拉列表获取并设置

编程入门 行业动态 更新时间:2024-10-17 19:34:00
本文介绍了流星下拉列表获取并设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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 } });

更多推荐

流星下拉列表获取并设置

本文发布于:2023-10-08 01:22:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流星   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!