Skip to content

Instantly share code, notes, and snippets.

@nightire
Created November 6, 2015 04:34
Show Gist options
  • Save nightire/2cb8c935f6d0049c493e to your computer and use it in GitHub Desktop.
Save nightire/2cb8c935f6d0049c493e to your computer and use it in GitHub Desktop.
原生选择控件在 Ember 2.x 里的基础用法
import Ember from 'ember';
export default Ember.Controller.extend({
choices: Ember.A([
'苹果', '橘子', '香蕉', '梨子'
]),
actions: {
selectChanged(value) {
alert(value)
}
}
});
<h1>演示:原生选择控件在 Ember 2.x 里的基础用法</h1>
<select onchange={{action 'selectChanged' value="target.value"}}>
{{#each choices as |choice|}}
<option value={{choice}} selected={{is-equal value choice}}>{{choice}}</option>
{{/each}}
</select>
import Ember from 'ember';
export function isEqual(params/*, hash*/) {
return (params[0] === params[1]);
}
export default Ember.Helper.helper(isEqual);
{
"version": "0.4.16",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment