Note that there are some explanatory texts on larger screens.

plurals
  1. POtext field filtering a list using ember + ember data
    primarykey
    data
    text
    <p>I'm new at using ember, but already familiar with it, basically following some tutorials here and there and reading the api docs. But tutorials don't go too deep into more complex topics.</p> <p>These are the details: I already implemented a web page that shows a list of items. The following are the relevant code excerpts from different parts of the app.</p> <pre><code>// the data model, the view and the controller App.Item = DS.Model.extend({ name: DS.attr('string') }); App.ItemsController = Ember.ArrayController.extend(); App.ItemsView = Ember.View.extend({ templateName: 'items' }) // in the router's corresponding route connectOutlets: function(router) { router.get('applicationController').connectOutlet('items', App.Item.find()) } // in the handlebars template &lt;ul class="items"&gt; {{#each content}} &lt;li&gt;{{name}}&lt;/li&gt; {{/each}} &lt;/ul&gt; </code></pre> <p>The data for this list is loaded remotely via ember-data (notice the <code>App.Item.find()</code> call in the route's <code>connectOutlet</code> method above) and a handlebar template displays it, and dynamically updates the list as the data changes. Up to here this is basic ember.</p> <p>Now I want to have a text field at the top of the list, and when the user types in this text field, the list should be updated, by filtering and showing only the items with a name that matches what the user is typing. The actual definition of what a matching name is, is irrelevant to this question. It could be those names that contain the typed string, or that start with it.</p> <p>I know my next step is to include a textfield view on top of the list in the handlebars template:</p> <pre><code>&lt;div class="search-bar"&gt; {{view Ember.TextField}} &lt;/div&gt; &lt;ul class="items"&gt; {{#each content}} &lt;li&gt;{{name}}&lt;/li&gt; {{/each}} &lt;/ul&gt; </code></pre> <p>So my questions at this point are the following:</p> <ul> <li>How do I refer to this text field in javascript code so I can attach a listener to it to detect when it changes?</li> <li>And more importantly, what do I need to do inside this event listener so the list gets filtered?</li> <li>I would like to know how to achieve it filtering data loaded locally, but also how to do it by loading the filtering data remotely everytime the user types.</li> </ul> <p>I actually need to implement something slightly more complex than this, but knowing how to do this will help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload