Dropdown list Meteor get and set

What is the best way to get and select values ​​from the drop-down list (as well as in the radio) in Meteor. I created an assistant:

Template.categories.helpers({ categories: ["facebook", "news", "tv", "tweets"] }); 

and in 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 the case of editing, I would like to evaluate it with the value coming from the database (for example, news) to be selected.

Thanks in advance.

+6
source share
2 answers

HTML template:

 <select id="category-select"> <option disabled="disabled" selected="selected">Please Select</option> {{#each categories}} <option value="{{this}}">{{this}}</option> {{/each}} </select> 

Js template:

 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 } }); 
+9
source
 Template.categories.helpers({ categories: function(){ return ["facebook", "news", "tv", "tweets"] } }); 

And you should consider changing the name and template helper, they should not be the same.

+1
source

Source: https://habr.com/ru/post/982521/


All Articles