Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // Usage
  2. {{#sc-each-random items=answers as |answer|}}
  3. <li class="list-group-item {{if answer.isCorrect 'bg-success text-success'}}">
  4. <span class="glyphicon {{if answer.isCorrect 'glyphicon-ok' 'glyphicon-remove'}}"></span> {{answer.text}}
  5. </li>
  6. {{/sc-each-random}}
  7.  
  8. // Component component.js
  9. import Ember from 'ember';
  10.  
  11. const {
  12. computed
  13. } = Ember;
  14.  
  15. export default Ember.Component.extend({
  16. items: null,
  17.  
  18. random: computed('items', function(items) {
  19. const randomItems = [];
  20. const maxIndex = items.length - 1;
  21.  
  22. while(randomItems.length !== items.length) {
  23. console.log(`Find random item from source and place in destination`);
  24. const randomIndex = Math.floor(Math.random() * maxIndex);
  25. const randomItem = items[randomIndex];
  26.  
  27. // if(randomItems.indexOf(randomItem) !== -1) {
  28. randomItems.push(randomItem);
  29. // }
  30. }
  31.  
  32. return randomItems;
  33. })
  34. });
  35.  
  36. // Component template.html
  37. {{#each random as |item index|}}
  38. {{yield item}}
  39. {{/each}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement