dimanche 15 novembre 2015

How to Update Ember Model to Show JSON Search Response

I feel like this answer to this question is trivial, but I am having a difficult time figuring out how to do this the 'Ember way'.

Quick problem background: I am creating a recipe app with Ember frontend and a Rails API backend. I am implementing a search feature to find recipes based on ingredients. I have already configured my Rails API endpoint which sends back the correct records as JSON.

    Ember.$.get('/recipes_query', {query: query})
    .then(function(reponse) {
        // Do something here
    });

Now all I need to do is display these. What I am confused about is how to handle the data when it is retrieved (or in other words, how to push these to the store, and then ONLY show the most recently retrieved results). I could push these results to the store and then use a filter to display the correct results, but this seems like an extra step - the JSON response already contains everything I need to display. What is the Ember convention for performing this simple task?

Aucun commentaire:

Enregistrer un commentaire