Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Usage
- {{#sc-each-random items=answers as |answer|}}
- <li class="list-group-item {{if answer.isCorrect 'bg-success text-success'}}">
- <span class="glyphicon {{if answer.isCorrect 'glyphicon-ok' 'glyphicon-remove'}}"></span> {{answer.text}}
- </li>
- {{/sc-each-random}}
- // Component component.js
- import Ember from 'ember';
- const {
- computed
- } = Ember;
- export default Ember.Component.extend({
- items: null,
- random: computed('items', function(items) {
- const randomItems = [];
- const maxIndex = items.length - 1;
- while(randomItems.length !== items.length) {
- console.log(`Find random item from source and place in destination`);
- const randomIndex = Math.floor(Math.random() * maxIndex);
- const randomItem = items[randomIndex];
- // if(randomItems.indexOf(randomItem) !== -1) {
- randomItems.push(randomItem);
- // }
- }
- return randomItems;
- })
- });
- // Component template.html
- {{#each random as |item index|}}
- {{yield item}}
- {{/each}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement