Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import { isBlank } from '@ember/utils'; import Component from '@ember/component'; import layout from '../../templates/components/freestyle/bootstrap-power-select'; import { task, timeout } from 'ember-concurrency'; export default Component.extend({ layout: layout, selectedItem: null, init() { this.names = ['Joe', 'Erin', 'Chad', 'Sam', 'Nathan', 'Isaac', 'Kevin', 'Ty', 'Tyler', 'Herb', 'Amy', 'Casey', 'Bret']; this.moreNames= [ { label: 'Adam', value: 1 }, { label: 'Betty', value: 2 }, { label: 'Chris', value: 3 }, { label: 'Dana', value: 4 }, { label: 'Ellen', value: 5 }, { label: 'Frank', value: 6 }, { label: 'Goerge', value: 7 }, { label: 'Heidi', value: 8 }, { label: 'Joe', value: 9 }, { label: 'Erin', value: 10 }, { label: 'Chad', value: 11 }, { label: 'Sam', value: 12 }, { label: 'Nathan', value: 13 }, { label: 'Isaac', value: 14 }, { label: 'Kevin', value: 15 }, { label: 'Ty', value: 16 }, { label: 'Tyler', value: 17 }, { label: 'Herb', value: 18 }, { label: 'Amy', value: 19 }, { label: 'Casey', value: 2 }, { label: 'Bret', value: 21 }, { label: 'Zeek', value: 22 }, { label: 'Paul', value: 23 }, { label: 'Jane', value: 24 }, { label: 'Kim', value: 25 }, { label: 'Jill', value: 26 }, { label: 'Tom', value: 27 }, { label: 'Will', value: 28 }, { label: 'Fred', value: 29 }, { label: 'Tim', value: 30 }, { label: 'Walt', value: 31 } ]; this._super(...arguments); }, searchTask: task(function * (searchText) { if (isBlank(searchText)) { return []; } yield timeout(500); return this.findNames(searchText); }).restartable(), findNames(containsText) { const moreNames = this.get('moreNames'); let foundNames = []; moreNames.forEach(nameObj => { if (nameObj.label.includes(containsText)) { foundNames.push(nameObj); } }); return foundNames; }, myMatcher(name, term) { return (name.label.toUpperCase().includes(term.toUpperCase()) || name.value === parseInt(term) ? 1 : -1); }, actions: { selectItem(selected) { this.set('selectedItem', selected); }, }, }); |