-
-
Save stefanpenner/8ee8962b5ea0795ff259 to your computer and use it in GitHub Desktop.
#12842
This file contains 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({ | |
elements: [ | |
{name: "Uranium"}, | |
{name: "Plutonium"}, | |
{name: "Francium"}, | |
{name: "Einstanium"} | |
], | |
searchQuery: '' | |
}); |
This file contains 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.Component.extend({ | |
// Just some basic styling to distinguish what belongs to the component | |
attributeBindings: ['style'], | |
style: 'border: 1px solid black;', | |
init() { | |
this._super(...arguments); | |
window.foo = this; | |
}, | |
searchQuery: '', // The search input | |
model: [], // All the elements to search in | |
// Return the elements that match the search query | |
filteredElements: Ember.computed('model.[]', 'searchQuery', function () { | |
let searchQuery = this.get('searchQuery').toLowerCase(); | |
let elements = this.get('model'); | |
return elements.filter(e => { | |
let name = e.name.toLowerCase(); | |
return name.indexOf(searchQuery) > -1; | |
}); | |
}), | |
// Return the number of elements that match the search query. This is the property we would like to be able to get from OUTSIDE the component | |
numberOfFilteredElements: Ember.computed('filteredElements', function () { | |
return this.get('filteredElements.length'); | |
}).readOnly() | |
}) |
This file contains 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.5.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.2.0", | |
"ember-data": "2.2.0", | |
"ember-template-compiler": "2.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment