Provides a helper to filter an array by a partial search string.
Provides a helper to filter an array by a partial search string.
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>
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, the search
helper will only return results where the case of the query matches.
exactMatch
(Boolean
, default: true
)
When set to true, the search
helper will only return results where the query matches the string exactly.
See the Contributing guide for details.
For more information on using ember-cli, visit https://ember-cli.com/.