Meteor Dropdown list get and set

前端 未结 2 741
情歌与酒
情歌与酒 2021-02-06 11:30

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({
    ca         


        
相关标签:
2条回答
  • 2021-02-06 11:50

    Template HTML:

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

    Template 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
        }
    });
    
    0 讨论(0)
  • 2021-02-06 11:56
    Template.categories.helpers({
        categories: function(){
            return ["facebook", "news", "tv", "tweets"]
        }
    });
    

    And you should consider changing template name and helper, they shouldn't be the same.

    0 讨论(0)
提交回复
热议问题