KonstantineGoudz / ember-dropdown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lister

This is an example of how to setup a dropdown selection in ember

Prerequisites

You will need to assign a controller for your route for this to work properly

quick example

  • create a route

    ember generate route drop
  • create a contoller

    ember generate controller drop-controller
  • associate the controller with the route in app/routes/drop.js

    import Route from '@ember/routing/route';
    
    export default Route.extend({
        controllerName: 'dropController', // the generated controller
        model() { // the model for the  route which will be passed to the conroller
            return {
                options: [
                    "test",
                    "cool",
                    "ffart"
                ]
            }
        }
    });
  • Implement the action in the controller app\controllers\drop-controller.js

    import Controller from '@ember/controller';
    
    export default Controller.extend({
        actions:{
            sel(val){
                alert(val)
            }
        }
    });
  • Finally in the app\templates\drop.hbs

    <select onchange={{action "sel" value="target.value"}} >
        {{#each model.options as |opt|}}
            <option value={{opt}}>{{opt}}</option>
        {{/each}}
    </select>
    {{outlet}}

About


Languages

Language:JavaScript 77.9%Language:HTML 22.1%