Skip to content

Instantly share code, notes, and snippets.

@barelyknown
Created November 20, 2015 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barelyknown/acce64e1e76cb3651bc0 to your computer and use it in GitHub Desktop.
Save barelyknown/acce64e1e76cb3651bc0 to your computer and use it in GitHub Desktop.
/app/controllers/state-matches.js
import Ember from 'ember';
export default Ember.Controller.extend({
matchingStates: [],
states: Ember.inject.service('states'),
actions: {
updateMatches(query) {
if (Ember.isPresent(query)) {
this.get('model.states').then((modelStates) => {
this.get('states').then((states) => {
const remaining = states.filter((state) => {
return !modelStates.contains(state);
});
this.set('matchingStates', remaining.filter((state) => {
return state.get('code').match(new RegExp(`^${query}`, 'i')) ||
state.get('name').match(new RegExp(`^${query}`, 'i'));
}));
});
});
} else {
this.set('matchingStates', []);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment