ember-search-helper
v2.0.0
Published
Provides a helper to filter an array by a search string.
Downloads
7
Maintainers
Readme
ember-search-helper
Provides a helper to filter an array by a partial search string.
Compatibility
- Ember.js v2.18 or above
- Ember CLI v2.13 or above
Examples
The search
helper can filter simple arrays:
// controller.js
export default Ember.Controller.extend({
fruits: ['Apple', 'Banana', 'Orange']
query: 'Oran'
});
{{input value=query on-key-press=(action (mut query))}}
<ul>
{{#each (search query fruits) as |fruit|}}
<li>{{fruit}}</li>
{{/each}}
</ul>
And arrays of objects:
// controller.js
export default Ember.Controller.extend({
fruits: [
{
name: 'Apple',
opinion: 'Meh'
},
{
name: 'Orange',
opinion: 'Yay'
},
{
name: 'Banana',
opinion: 'Nay'
}
],
searchProperties: ['name', 'opinion'],
query: 'ay'
});
{{input value=query on-key-press=(action (mut query))}}
<ul>
{{#each (search query fruits properties=searchProperties) as |fruit|}}
<li>{{fruit.name}}</li>
{{/each}}
</ul>
Options
properties
(Array
, default:[]
) An array of properties you would like to search by. Only useful if you are searching an array of objects.caseSenstive
(Boolean
, default:false
) When set to true, thesearch
helper will only return results where the case of the query matches.exactMatch
(Boolean
, default:true
) When set to true, thesearch
helper will only return results where the query matches the string exactly.
Contributing
See the Contributing guide for details.
License
For more information on using ember-cli, visit https://ember-cli.com/.