dimanche 19 février 2017

Ember: handling JSON response from ember-network promise in component

I'm trying to implement a simple autosuggest in a component. I'm trying to use fastboot and therefore am using ember-network to communicate with my API. Not using ember-data. Whether or not this is the "ember" way to do it is a different question...I'm just trying to get this to work.

My component JS:

import Ember from 'ember';
import fetch from 'ember-network/fetch';

export default Ember.Component.extend({
    searchText: null,

    loadAutoComplete(query) {
        let suggestCall = 'http://ift.tt/2mdbS15' + query;
        return fetch(suggestCall).then(function(response) {
            return response.json();
        });     
    },

    searchResults: Ember.computed('searchText', function() {
        let searchText = this.get('searchText');
        if (!searchText) { return; }
        let searchRes = this.loadAutoComplete(searchText);
        return searchRes;
    })
});

And in the template:





<li> </li>


The template log directive is outputting this in my console:

console

The data is in "suggestions", so I know the fetch is working. I just can't figure out how to get at it. I can't loop over '_result'. What do I need to do to parse this and use it in a template?




Aucun commentaire:

Enregistrer un commentaire