Created
May 10, 2016 08:33
-
-
Save jgwhite/7a786ab059efed0d9e894cdabad070c4 to your computer and use it in GitHub Desktop.
Pick Random Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const PickRandom = Ember.Component.extend({ | |
tagName: '', | |
data: null, | |
choice: null, | |
init() { | |
this._super(); | |
this.pick(); | |
}, | |
pick() { | |
let data = this.get('data'); | |
let idx = Math.floor(Math.random() * data.length); | |
this.set('choice', data[idx]); | |
} | |
}); | |
PickRandom.reopenClass({ | |
positionalParams: ['data'] | |
}); | |
export default PickRandom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
data: [1,2,3,4,5,6,7,8,9,10], | |
choice: null, | |
init() { | |
this.pick(); | |
}, | |
pick() { | |
let data = this.get('data'); | |
let idx = Math.floor(Math.random() * data.length); | |
this.set('choice', data[idx]); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.8.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.5.1", | |
"ember-data": "2.5.2", | |
"ember-template-compiler": "2.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment