Skip to content

Instantly share code, notes, and snippets.

@rtablada
Last active May 2, 2017 12:48
Show Gist options
  • Save rtablada/280778b093768172cf43 to your computer and use it in GitHub Desktop.
Save rtablada/280778b093768172cf43 to your computer and use it in GitHub Desktop.
Show Select 2.0
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
vehicleIndex: 0,
vehicle: Ember.computed('vehicleIndex', function() {
return this.get('vehicles')[this.get('vehicleIndex')];
}),
vehicles: [
{name: 'Ford', year: 1953},
{name: 'Chevy', year: 1952}
],
});
<select onchange={{action (mut vehicleIndex) value="target.value"}}>
{{#each vehicles as |vehicleChoice index|}}
<option value={{ index }} selected={{is-eq vehicleIndex index}}>{{vehicleChoice.name}}</option>
{{/each}}
</select>
<p>
Vehicle: {{vehicle.name}}
</p>
<p>
Year: {{vehicle.year}}
</p>
import Ember from 'ember';
export function isEq(params/*, hash*/) {
return params[0] === params[1];
}
export default Ember.Helper.helper(isEq);
{
"version": "0.4.9",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment