Created
April 5, 2017 05:35
-
-
Save lennyburdette/366b412abadfbc9f0363fd96603d03aa to your computer and use it in GitHub Desktop.
sq-field-input-searchable filtering
This file contains hidden or 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'; | |
| function defaultFilter(options, input) { | |
| return options.filter(v => v.startsWith(input)); | |
| } | |
| export default Ember.Component.extend({ | |
| didReceiveAttrs() { | |
| this.set('filteredOptions', this.get('options').slice()); | |
| }, | |
| input(e) { | |
| if (this.get('inputChanged')) { | |
| this.sendAction('inputChanged', e.target.value); | |
| } else { | |
| this.set('filteredOptions', defaultFilter(this.get('options'), e.target.value)); | |
| } | |
| } | |
| }); |
This file contains hidden or 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({ | |
| allOptions: 'red yellow orange green blue indigo violet'.w(), | |
| options1: Ember.computed(function() { | |
| return this.get('allOptions').slice(); | |
| }), | |
| options2: Ember.computed(function() { | |
| return this.get('allOptions').slice(); | |
| }), | |
| actions: { | |
| inputChanged(input) { | |
| const options = this.get('allOptions').filter(v => v.startsWith(input)); | |
| this.set('options2', options); | |
| } | |
| } | |
| }); |
This file contains hidden or 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.12.1", | |
| "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.12.0", | |
| "ember-template-compiler": "2.12.0", | |
| "ember-testing": "2.12.0" | |
| }, | |
| "addons": { | |
| "ember-data": "2.12.1" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment